Dan.A Dan.A - 9 months ago 55
Vb.net Question

How to change the order controls are read in .Net?

I have a very textbox rich heavy panel (approx ~ 25 textboxes) for which I want to retrieve all my text from.

I've done so using this loop.

Dim AllItemsArray As New ArrayList
For Each txt As Control In Panel2.Controls
If txt.GetType Is GetType(TextBox) Then
End If

However, for some odd reason it reads the textboxes in a completly random order which makes using the information extremely difficult.
I thought that the textboxes were read in the order they are made, but so far it hasn't done so.

Does anyone have any suggestions as to how I can alter it so that it reads the textboxes in order?

IE. textbox1.text, textbox2.text ...etc

and not

textbox5.text, textbox2.text, textbox 20 ....etc


Answer Source

This gets the controls in Tab order sequence. It also gets controls that are in containers, i.e. GroupBox.

    Dim ctrl As Control = Me.GetNextControl(ctrl, True)
    Do While ctrl IsNot Nothing

        ctrl = Me.GetNextControl(ctrl, True)