How do I control the focus order for TextBoxes inside a panel?

Agnieszka Polec picture Agnieszka Polec · Jul 26, 2014 · Viewed 8.1k times · Source

I have a Form with many TextBoxes. I need some TextBoxes inside one group, and other text boxes inside another group. By group, I just need a way to make these TextBoxes appear to belong with each other.

I made two Panels and added the TextBoxes to them. Then, I placed a border around these Panels.

However, my problem is that when I press Tab, the focus doesn't go to the next TextBox, but rather it goes in a random order to another TextBox. Sometimes the next TextBox is inside the first Panel, other times it is in the second Panel. How can I control the focus order?

This is an image to illustrate my point:

an image to illustrate my point

Answer

Shell picture Shell · Jul 26, 2014

Tab order should be set like this. Both top container panel should have TabIndex 0 and 1 respectively and its child control should have TabIndex prefix by their parent control Tab Index. ie. if the Panel1 has TabIndex 0 then its child controls should have TabIndex 0.0,0.1,0.2,0.3...

NOTE: make sure that if the Tab Stop property of any control is set to false then cursor will not move into that control. In that case TabIndex will not work.

enter image description here