-
Controlcollections
hi again.
Just used a control collection to parse all the textboxs on my form, and from what i can see it parse's in reverse order ?? is this correct ?
is there anyway to make it follow the tab order or something so that it does it the right way round ?
thanks
-
When you say parse, what code are you using?
You use an enumarator? In that case it should start from the beginning, or one element before the beginning I think. The foreach should do the same thing.
Never used a ControlCollection, so dunno for sure. But post the parsing code
-
maybe parse was the wrong word to use in this case. basically when i use this piece of code it appears to start going through the controls in reverse order. there is a button and several text boxs that need checking and using the following seems to start at the button and work up the form.
Code:
Control.ControlCollection ctrls = this.Controls;
foreach (Control ctrl in ctrls)
{
if (ctrl.GetType() == typeof(TextBox) && ctrl.Text == "")
{
MessageBox.Show("Please complete all Information required!");
ctrl.Focus();
return;
}
}
not a major problem but would prefer to go down the page in a ogical order for unfilled textboxs.
-
If you see the code generated you will see that there are lines like
this.Controls.Add(...)
or something like that. So you can change the order that the controls are added in the this.Controls list. That is the best thing to do
-
thanks for that - i can see the problem - dont know why they have been added to the form in the wrong order maybe just the way the IDE deals with it :)
-
I believe they are added by the order you create them. Or your IDE has a weird way for ordering them (in which case slap it and show it who's boss)