Tab indexes with dynamic controls not working

T

Tom

I have a wierd situation... Have a Windows Form with a number of text boxes,
combo boxes, etc. After the user enters a value inside my first text box
(tabindex 0), I then dynamically create a number of label - Textbox
combination fields inside a panel in the form. During the creation of those
fields I set the TabIndex to a incrementing number (that is between current
tab indexes) and the TabStop to True. However, once I create these dynamic
fields the tabbing sequence goes all to heck. For instance, tabbing on the
first dynamically created text box (tab index 21) causes the focus to go
back to the first text box on the screen! (tab index 0) Tabbing from there
causes focus to go to one of the buttons on the bottom of the screen (rather
than tab index 2).... etc etc etc.

This is driving me crazy.... I even went so far as to hook the KeyPress
events for these fields and use SelectNextControl if the key is a tab - but
that doesn't work either. The tab numbers look OK, but it is as though the
tab sequence doesn't matter anymore!

Anyone got any ideas on this? Otherwise, I may have to code specifically for
EACH control and set the focus accordingly (which sucks).

Tom
 
J

Jeff Johnson [MVP: VB]

Never mind, I figured it out.

For those who may search this group looking for the answer to the same
issue, could you give a brief description of the solution?
 
T

Tom

Sure.... Tab indexes work from the outside in... I.E. Let's say I have two
group boxes on a form, and then two buttons on the form after the group
boxes. The tab sequence would be GB1:0, GB2:1, Button1:3, Button2:4. Then
items WITHIN those two group boxes would start again with tab index 0.
Again, for instance, if you had a text box within the first group box, it's
tab index would be 0. That also applies if you have a panel within the group
box. That index would be 0, and items within the panel would start as 0.

Previously, I had just assumed that tab indexes start at 0 and go upward for
every control, which is not the case in .NET. Confusing to describe, but
makes sense once you 'see the light' :)

Tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top