# What's the secret of tab control order

**URL:** <https://forum.xojo.com/t/whats-the-secret-of-tab-control-order/16834>\
**Category:** Getting Started\
**Created:** [May 27, 2014, 7:42am UTC](https://forum.xojo.com/t/whats-the-secret-of-tab-control-order/16834 "2014-05-27T07:42:26Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Clare\_Strange](https://forum.xojo.com/letter_avatar_proxy/v4/letter/c/4da419/32.png) [@Clare\_Strange](https://forum.xojo.com/u/Clare_Strange)\
**Post date:** [May 27, 2014, 7:42am UTC](https://forum.xojo.com/t/whats-the-secret-of-tab-control-order/16834/1 "2014-05-27T07:42:26Z")

</div>

Hi, I have a very small Window:

[link text](https://xojo.io/435c8b1a6685)

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?

---

<div class="post-metadata">

**Author:** ![Tim\_Hare](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_hare/32/176_2.png) [@Tim\_Hare](https://forum.xojo.com/u/Tim_Hare)\
**Post date:** [May 27, 2014, 7:54am UTC](https://forum.xojo.com/t/whats-the-secret-of-tab-control-order/16834/2 "2014-05-27T07:54:25Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Clare\_Strange](https://forum.xojo.com/letter_avatar_proxy/v4/letter/c/4da419/32.png) [@Clare\_Strange](https://forum.xojo.com/u/Clare_Strange)\
**Post date:** [May 27, 2014, 8:14am UTC](https://forum.xojo.com/t/whats-the-secret-of-tab-control-order/16834/3 "2014-05-27T08:14:01Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Tim\_Hare](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_hare/32/176_2.png) [@Tim\_Hare](https://forum.xojo.com/u/Tim_Hare)\
**Post date:** [May 27, 2014, 9:06am UTC](https://forum.xojo.com/t/whats-the-secret-of-tab-control-order/16834/4 "2014-05-27T09:06:39Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Clare\_Strange](https://forum.xojo.com/letter_avatar_proxy/v4/letter/c/4da419/32.png) [@Clare\_Strange](https://forum.xojo.com/u/Clare_Strange)\
**Post date:** [May 27, 2014, 9:20am UTC](https://forum.xojo.com/t/whats-the-secret-of-tab-control-order/16834/5 "2014-05-27T09:20:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [May 27, 2014, 12:03pm UTC](https://forum.xojo.com/t/whats-the-secret-of-tab-control-order/16834/6 "2014-05-27T12:03:27Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Christian\_Schmitz](https://forum.xojo.com/user_avatar/forum.xojo.com/christian_schmitz/32/158_2.png) [@Christian\_Schmitz](https://forum.xojo.com/u/Christian_Schmitz)\
**Post date:** [May 27, 2014, 12:07pm UTC](https://forum.xojo.com/t/whats-the-secret-of-tab-control-order/16834/7 "2014-05-27T12:07:01Z")

</div>

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

if asc(key) = 9 then

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [May 27, 2014, 12:20pm UTC](https://forum.xojo.com/t/whats-the-secret-of-tab-control-order/16834/8 "2014-05-27T12:20:39Z")

</div>

[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 😉

---

<div class="post-metadata">

**Author:** ![Clare\_Strange](https://forum.xojo.com/letter_avatar_proxy/v4/letter/c/4da419/32.png) [@Clare\_Strange](https://forum.xojo.com/u/Clare_Strange)\
**Post date:** [May 28, 2014, 2:27am UTC](https://forum.xojo.com/t/whats-the-secret-of-tab-control-order/16834/9 "2014-05-28T02:27:36Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Tim\_Hare](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_hare/32/176_2.png) [@Tim\_Hare](https://forum.xojo.com/u/Tim_Hare)\
**Post date:** [May 28, 2014, 2:51am UTC](https://forum.xojo.com/t/whats-the-secret-of-tab-control-order/16834/10 "2014-05-28T02:51:50Z")

</div>

> [@92574:@Cliff Strange](#):
>
> I already have a Select Case for all the characters I want in the field, each Returning False

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

```auto
if Asc(Key) = 9 then 
```

---

<div class="post-metadata">

**Author:** ![Clare\_Strange](https://forum.xojo.com/letter_avatar_proxy/v4/letter/c/4da419/32.png) [@Clare\_Strange](https://forum.xojo.com/u/Clare_Strange)\
**Post date:** [May 28, 2014, 3:09am UTC](https://forum.xojo.com/t/whats-the-secret-of-tab-control-order/16834/11 "2014-05-28T03:09:05Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Jason\_King](https://forum.xojo.com/letter_avatar_proxy/v4/letter/j/e480ec/32.png) [@Jason\_King](https://forum.xojo.com/u/Jason_King)\
**Post date:** [May 28, 2014, 3:29am UTC](https://forum.xojo.com/t/whats-the-secret-of-tab-control-order/16834/12 "2014-05-28T03:29:43Z")

</div>

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

```auto
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.

```auto
<snip>
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 😉

---

<div class="post-metadata">

**Author:** ![Clare\_Strange](https://forum.xojo.com/letter_avatar_proxy/v4/letter/c/4da419/32.png) [@Clare\_Strange](https://forum.xojo.com/u/Clare_Strange)\
**Post date:** [May 28, 2014, 3:50am UTC](https://forum.xojo.com/t/whats-the-secret-of-tab-control-order/16834/13 "2014-05-28T03:50:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Jason\_King](https://forum.xojo.com/letter_avatar_proxy/v4/letter/j/e480ec/32.png) [@Jason\_King](https://forum.xojo.com/u/Jason_King)\
**Post date:** [May 28, 2014, 3:52am UTC](https://forum.xojo.com/t/whats-the-secret-of-tab-control-order/16834/14 "2014-05-28T03:52:33Z")

</div>

You’re welcome, glad I could help.

---

<div class="post-metadata">

**Author:** ![Tim\_Hare](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_hare/32/176_2.png) [@Tim\_Hare](https://forum.xojo.com/u/Tim_Hare)\
**Post date:** [May 28, 2014, 4:40am UTC](https://forum.xojo.com/t/whats-the-secret-of-tab-control-order/16834/15 "2014-05-28T04:40:42Z")

</div>

I would stick it in sequence with your other values.

```auto
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).

---

<div class="post-metadata">

**Author:** ![Clare\_Strange](https://forum.xojo.com/letter_avatar_proxy/v4/letter/c/4da419/32.png) [@Clare\_Strange](https://forum.xojo.com/u/Clare_Strange)\
**Post date:** [May 28, 2014, 4:57am UTC](https://forum.xojo.com/t/whats-the-secret-of-tab-control-order/16834/16 "2014-05-28T04:57:45Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Clare\_Strange](https://forum.xojo.com/letter_avatar_proxy/v4/letter/c/4da419/32.png) [@Clare\_Strange](https://forum.xojo.com/u/Clare_Strange)\
**Post date:** [May 28, 2014, 5:04am UTC](https://forum.xojo.com/t/whats-the-secret-of-tab-control-order/16834/17 "2014-05-28T05:04:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Tim\_Hare](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_hare/32/176_2.png) [@Tim\_Hare](https://forum.xojo.com/u/Tim_Hare)\
**Post date:** [May 28, 2014, 5:57am UTC](https://forum.xojo.com/t/whats-the-secret-of-tab-control-order/16834/18 "2014-05-28T05:57:06Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![Clare\_Strange](https://forum.xojo.com/letter_avatar_proxy/v4/letter/c/4da419/32.png) [@Clare\_Strange](https://forum.xojo.com/u/Clare_Strange)\
**Post date:** [May 28, 2014, 7:06am UTC](https://forum.xojo.com/t/whats-the-secret-of-tab-control-order/16834/19 "2014-05-28T07:06:27Z")

</div>

Good idea, thanks!

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [October 29, 2020, 5:14pm UTC](https://forum.xojo.com/t/whats-the-secret-of-tab-control-order/16834/20 "2020-10-29T17:14:40Z")

</div>


