Setting focus to first control in tab on container

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!
 
G

Guest

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

James Hancock

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

Guest

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.
 

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

Top