What's the secret of tab control order

Hi, I have a very small Window:

link text

I must admit to playing around with the tab order, because since the Window was created the Order No. Text Field (which is subclassed to allow numbers only) can never be tabbed into.

The Class Name Field is selected when the Window opens, I can type into it, hit the tab key and I am in the Class Number field, type into it, then I can tab until I am blue in the face, and I never get transferred to the Order No. Text Field.

At present, starting from the top of the tab order dialog box I have the Popup Control, the Class Name Text Field, the Class Number Text Field, and the Class Order Text Field, all the other controls are below these four.

What could possible be the cause of not being able to tab into the bottom Text Field?

Is TabStop turned off for that field? Click the gear icon to get to the advanced settings. TabIndex is editable there, as well. What do you get when you click the Show Tab Order icon?

Hi Tim

Thanks for the quick reply. The following is what I have from the Show Tab Order icon in order from the top of the list, with right over to the right the tab order index from the gear icon:

selectCatPopup 0
ClassNameField 1
ClassNumField 2
ClassNumLabel -(Class No:) 5
ClassNameLabel -(Class Name:) 4
OrderNumField 3
lastClassLabel -(Last Class:) 6
OrderNumLabel -(Order No:) 7
DoneButton -(Done) 8
OKButton -(OK) 9

I did notice that the OrderNumField was not in the right place (although its tab index was correct), I changed that before replying and that didn’t make any difference.

It looks like it should be working. I can’t reproduce the problem. Any rearrangement of the Show Tab Order list results in the right tab order. It really should be working for you.

Well, I guess I will just keep playing with it for a while. One thing I have noticed a couple of times with Xojo is that something may not be working quite how I expect it to (like this), so I sort of live with it. At the end of the day I quit out of Xojo and shut down my Mac. Then when I get back to it the next day, it is working as it should.

Whilst I was developing this window, even though it is really small, I played around with the controls and their names and position for quite a while. (I am sad to say that I am not into planning my apps, they sometimes just grow like topsy). I wonder if I manage to confuse Xojo (does it write temp files whilst in the debugger?) and then after a shutdown of both Xojo and the Mac, things get cleared out, and we start with a fresh slate?

Anyway, I have thought that I may rename this window (to keep the code), and create it again (in order) and see if that helps.

Thanks very much for taking the time to look at my post (and others that I have posted, I must add). This forum is really helpful and friendly compared with some I have been on. I am trying to post less and trying to work things out. But this really stumped me.

Another post reported the same problem a while ago. I offered then a simple workaround :

Add to the Class No field Keydown this code :

If Key = chr(9) then OrderNo.Setfocus Return True end if

It does not explain the bug or shed any light on the tab order mysteries, but it alleviates the problem.

better use ASC than CHR. string comparison is not exact.

if asc(key) = 9 then

[quote=92307:@Christian Schmitz]better use ASC than CHR. string comparison is not exact.

if asc(key) = 9 then[/quote]

Control characters do not have case. But asc(9) is fine with me :wink:

Hi Michel

Asc(9) returned a Parameters are not compatible with this function error.

I cannot quite work out where to put the code. Of course in the keydown event I already have a Select Case for all the characters I want in the field, each Returning False; so I put it in the Else part. But I can’t use the name of the Field (OrderField.SetFocus) because it says OrderField does not Exist. If I put Me.SetFocus then it still doesn’t work.

Any more help would be appreciated.

Does that mean that you return True to disallow everything else? That would include the Tab key. The correct syntax (as given by Christian) is

if Asc(Key) = 9 then 

Hi Tim

I am sorry, but I still don’t understand where to put this code. In my subclassed TextField I don’t have a Keydown Event (obviously)

So in the actual class itself this is the code I have put:

Select Case Asc(Key) Case 8 Return False Case 13 Return False Case 32 Return False Case 48 Return False Case 49 Return False Case 50 Return False Case 51 Return False Case 52 Return False Case 53 Return False Case 54 Return False Case 55 Return False Case 56 Return False Case 57 Return False End Select If Asc(Key) = 9 Then Me.Setfocus Return True End If

I have put Me even though I know that applies both of the subclasses Text Field, but it still doesn’t work. Other than putting Me I don’t know how to refer to the TextField in question.

In your subclassed textfield you could create a Keydown event definition with the same signature as the standard keydown event, i.e.

Keydown(key as string) as boolean

Then in the select case you could add case else to the bottom before the end select and raise your custom event, i.e.

Case 56
  Return False
Case 57
  Return False
Case else
  Return RaiseEvent Keydown(key)
End Select

Then when you drag an instance of the class onto a window you can implement your Keydown event and you will receive the custom event when asc(Key) is not 8, 13, 32, etc. Then you will have to check if asc(key) = 9 from the window and you can set the focus to the correct textfield/control.

Hopefully this makes sense and doesn’t confuse you more :wink:

Wow, thank you Jason.

I must admit that had me a little excited for a second figuring out where to put what. But Xojo helped out by throwing up error messages all over the place, until I finally got it figured out. Now it works perfectly!!

I suppose it would be interesting to know why it didn’t work in the first place. I did try recreating the Window. Firstly I just put three TextFields on the Window, and I could tab to each of them. Then I added the other controls, and Still I could tab around OK. Finally I added the code, and suddenly once again I couldn’t tab to the third TextField. That really only leave one cause - there is something in my code that is causing this. However, although normally I try to be a perfectionist, in this case I am going to accept a workaround.

Many thanks again.

You’re welcome, glad I could help.

I would stick it in sequence with your other values.

Select Case Asc(Key)
  Case 8
    Return False
  Case 9
    Return False
  Case 13
    Return False

But incidentally, why are you testing for 8? That’s an odd key to check for. And you really should be testing for 3 as well (Enter key on the keypad).

OK I will try that, maybe that is the sole cause of that TextField not being selected, because I am not allowing the tab key. As far as I know 8 is the backspace (delete) key. I want to allow people to correct any typing error they make without having to start over.

Tim, I put Case 9 into the Keydown Event and removed the Raised Event thingy that I did with help from Jason, and it worked. So that was the problem all along, the fact that I was blocking the tab key, because the Field just before the one in question was a NumbersOnly subclassed Text Field as well.

I am pleased that this is finally sorted out without any “fiddles” and Xojo is happy - so am I.

But I am also glad that I found out about the Raised Event procedure, as it may come in hand some time in the future.

Of course! I even have that in my own code, but forgot all about it. I was thinking 7, which is the bell, and wondering why you were testing for it. In that case, you might want to allow 28 and 29 (left/right arrow keys).

Good idea, thanks!