C Board  

Go Back   C Board > General Programming Boards > C# Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 12-17-2008, 12:58 PM   #1
Registered User
 
Join Date: Oct 2008
Posts: 85
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
deviousdexter is offline   Reply With Quote
Old 12-17-2008, 01:29 PM   #2
Registered User
 
C_ntua's Avatar
 
Join Date: Jun 2008
Posts: 1,285
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
C_ntua is offline   Reply With Quote
Old 12-19-2008, 04:18 AM   #3
Registered User
 
Join Date: Oct 2008
Posts: 85
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.
deviousdexter is offline   Reply With Quote
Old 12-19-2008, 04:35 AM   #4
Registered User
 
C_ntua's Avatar
 
Join Date: Jun 2008
Posts: 1,285
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
C_ntua is offline   Reply With Quote
Old 12-19-2008, 05:44 AM   #5
Registered User
 
Join Date: Oct 2008
Posts: 85
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
deviousdexter is offline   Reply With Quote
Old 12-19-2008, 08:19 AM   #6
Registered User
 
C_ntua's Avatar
 
Join Date: Jun 2008
Posts: 1,285
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)
C_ntua is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump


All times are GMT -6. The time now is 09:53 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22