Setting focus to first control in tab on container

  • Thread starter Thread starter James Hancock
  • Start date Start date
J

James Hancock

Does anyone know how to figure out which is the first control in the tab
order on a container programatically without sorting every item via tab
order number manually?

I need to set the focus to the first item in a container control
programmatically and the .Controls property is not in tab order, it's in
whatever it feels like order.

Thanks!
 
In the WIndows form designer code, each control is added in the reverse order
of the collection. For instance the collection created by:

Me.Controls.Add(Me.TextBox4)
Me.Controls.Add(Me.TextBox3)
Me.Controls.Add(Me.TextBox2)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.Button1)

will iterate from the bottom up.

Will this always work? Will the Forms designer leave your code alone? I
don't know. I wouldn't recommend this because I can't answer those but it
might be safe.
 
That's the problem. The order that they are added is not necessarily the tab
order. I just need to find out what the first item in the tab order is.
 
You would have to add them in reverse Tab order.

James Hancock said:
That's the problem. The order that they are added is not necessarily the tab
order. I just need to find out what the first item in the tab order is.
 
Back
Top