The order of controls in a groupbox
-
I have been googling for an answer on this and I just can't find it. I have a groupbox that contains several checkboxes. When I go through a foreach loop, the order in the groupbox.controls seems to have no order, but are in the same order everytime.
foreach(CheckBox s in grpGroup.Controls) { if(s.Checked) { blReports[intx] = true; } intx++; }
What is the logical order of the groupbox.controls collection? It is not tab order, nor creation order. I just can't figure this out. Thanx in advance!Jude
-
I have been googling for an answer on this and I just can't find it. I have a groupbox that contains several checkboxes. When I go through a foreach loop, the order in the groupbox.controls seems to have no order, but are in the same order everytime.
foreach(CheckBox s in grpGroup.Controls) { if(s.Checked) { blReports[intx] = true; } intx++; }
What is the logical order of the groupbox.controls collection? It is not tab order, nor creation order. I just can't figure this out. Thanx in advance!Jude
This is the order in which items are inserted in the Controls collection of group box. Only point is that you get controls in reverse order, which means if you have controls ctrl1, ctrl2 and ctrl3 added. You will get ctrl3, ctrl2 and ctrl1 using 'for each' loop. -Ajay.
------------------------- www.componentone.com -------------------------
-
This is the order in which items are inserted in the Controls collection of group box. Only point is that you get controls in reverse order, which means if you have controls ctrl1, ctrl2 and ctrl3 added. You will get ctrl3, ctrl2 and ctrl1 using 'for each' loop. -Ajay.
------------------------- www.componentone.com -------------------------
Ajay K. Singh wrote:
This is the order in which items are inserted in the Controls collection of group box.
My question is what controls the order in which the items are inserted into the Controls collection. The creation order in the code is cntl1,cntl2,cntl3,cntl4,cntl5,cntl6,cntl7. The order of the foreach loop is 7,2,4,5,1,3,6. Thanx for the reply!
Jude
-
I have been googling for an answer on this and I just can't find it. I have a groupbox that contains several checkboxes. When I go through a foreach loop, the order in the groupbox.controls seems to have no order, but are in the same order everytime.
foreach(CheckBox s in grpGroup.Controls) { if(s.Checked) { blReports[intx] = true; } intx++; }
What is the logical order of the groupbox.controls collection? It is not tab order, nor creation order. I just can't figure this out. Thanx in advance!Jude
If you want to have a more logical order that you have more control of: for(int i=0;i { Checkbox s=(CheckBox)grpGroup.Controls(i); if(s.Checked) { blReports[intx] = true; } intx++; } Regards, Thomas Stockwell Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. Visit my homepage Oracle Studios[^]
-
Ajay K. Singh wrote:
This is the order in which items are inserted in the Controls collection of group box.
My question is what controls the order in which the items are inserted into the Controls collection. The creation order in the code is cntl1,cntl2,cntl3,cntl4,cntl5,cntl6,cntl7. The order of the foreach loop is 7,2,4,5,1,3,6. Thanx for the reply!
Jude
Hi, AFAIK the order of the controls is not the declaration order, not the creation order, it is the order in which they get added to their parents Controls collection, which depends a lot on your Designer interaction. You can modify the order by (carefully) editing the designer-generated file (xxx.designer.cs). You can also set a new order by: -first removing all the controls (i.e. move them from the groupbox to the form itself); -then add them again, one by one, in the desired order (i.e. move them back from the form to the groupbox). :)
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips: - before you ask a question here, search CodeProject, then Google; - the quality and detail of your question reflects on the effectiveness of the help you are likely to get; - use PRE tags to preserve formatting when showing multi-line code snippets.
-
I have been googling for an answer on this and I just can't find it. I have a groupbox that contains several checkboxes. When I go through a foreach loop, the order in the groupbox.controls seems to have no order, but are in the same order everytime.
foreach(CheckBox s in grpGroup.Controls) { if(s.Checked) { blReports[intx] = true; } intx++; }
What is the logical order of the groupbox.controls collection? It is not tab order, nor creation order. I just can't figure this out. Thanx in advance!Jude
Thanx for all of the replies! From what I gather it is VS dependent in which order controls are added to the groupbox.controls collection. I decided to go with a switch based on the control name:
if(s.Checked) { switch(s.Name) { case "cboDepr": blReports[0] = true; break;...
Not very elegant, but gets the job done. Thanx again!Jude
-
I have been googling for an answer on this and I just can't find it. I have a groupbox that contains several checkboxes. When I go through a foreach loop, the order in the groupbox.controls seems to have no order, but are in the same order everytime.
foreach(CheckBox s in grpGroup.Controls) { if(s.Checked) { blReports[intx] = true; } intx++; }
What is the logical order of the groupbox.controls collection? It is not tab order, nor creation order. I just can't figure this out. Thanx in advance!Jude
Hi you can check in mm.designer.cs file for the answer, there one array have ur control sequence.
Cheers,Earn and Enjoy RRave MCTS,MCPD http://ravesoft.blogspot.com
-
Hi you can check in mm.designer.cs file for the answer, there one array have ur control sequence.
Cheers,Earn and Enjoy RRave MCTS,MCPD http://ravesoft.blogspot.com
Is that some type of 2005 or + thing? I am still using VS2003..I don't program any big projects in VS and have kept the staple w/ .net 1.1. I got it working with my non-elegant code :) Thanx for the reply! And thank you to all who have replied to this thread for not being an ass!
Jude