|
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)<br />
{<br />
if(s.Checked)<br />
{<br />
blReports[intx] = true;<br />
}<br />
intx++;<br />
}<br />
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
-------------------------
|
|
|
|
|
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.
|
|
|
|
|
If you want to have a more logical order that you have more control of:
for(int i=0;i<grpgroup.controls.count;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[^]
|
|
|
|
|
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)<br />
{<br />
switch(s.Name)<br />
{<br />
case "cboDepr":<br />
blReports[0] = true;<br />
break;...
Not very elegant, but gets the job done.
Thanx again!
Jude
|
|
|
|
|
Hi
you can check in mm.designer.cs file for the answer, there one array have ur control sequence.
|
|
|
|
|
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
|
|
|
|
|
Hey I am trying to use System.Threading.Thread.Sleep() and I am not getting expected results.
I am trying to use it as a delay
turn RTS on<br />
System.Threading.Thread.Sleep(5);<br />
turn RTS off
I have an o-scope hooked to the RTS line and I would expect that the RTS should go on and off anytime over 5 milliseconds (due to windows timing issues), but I would not expect to see it take anytime less than 5 milliseconds.
However, I am seeing results anywhere from just under 1 millisecond up to 20 milliseconds. Again if it was just 4 milliseconds (because of the resolution, i thought maybe we could see something as long as it was greater than 4) to whatever, I would be fine with that, but it is returning in less than 4 milliseconds down to one millisecond even!
Just for giggles I set up this
<br />
Using System.Diagnostics;<br />
Using System.Threading;<br />
<br />
long startTime,finishTime,diff;<br />
float elapsed;<br />
<br />
for (int x = 1; x <=10 ; x++)<br />
{<br />
startTime = Stopwatch.GetTimeStamp();<br />
Thread.Sleep(x);<br />
finishTime = Stopwatch.GetTimeStamp();<br />
diff = finishTime - startTime; <br />
elapsed = diff / 10000; <br />
Console.Write(x + " > " + elapsed + "ms > " + diff);<br />
}
And am seeing very similar (and stragne) results.
Is this just a bug in the the sleep function or what? Is there another function that I can call instead? (Don't even think about writing that I should be polling---don't get me started--, I am working in an environment where milliseconds difference are noticable, polling would be such a time killer)
Thanks
Brandy
|
|
|
|
|
aei_totten wrote: Is this just a bug in the the sleep function or what?
I don't believe so. I believe it is documented to have inconsistent results for anything less that 55 mills. Granted I haven't looked at it for many years but I think that's what it said at one time. I also believe that are higher resolution timers[^] you should use for the type of requirements you have.
led mike
|
|
|
|
|
|
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.
|
|
|
|
|
Windows is not a real-time O/S. The resolution of those timers is not guaranteed and can vary from system to system, and even vary due to system load.
If you want to grab analog/digital data at a consistance rate, you'd have to use hardware dedicated to the task. This would be something like an Analog/Digital converter board or some other PCI/PCIx data acquisition board that comes with an API to do the data capture/buffering independant of the system CPU.
|
|
|
|
|
aei_totten wrote: Thread.Sleep() not working
Of course, it is Thread.Sleep(), it isn't Thread.Work().
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.
|
|
|
|
|
Hi,
I have a Class named Global and I'm Trying to access Form2 of my App. But sadly I can not. Normally I would use it as
Form2 frm = New Form2();
But I just cannot get Form2 on that Class
- Stop thinking in terms of limitations and start thinking in terms of possibilities -
|
|
|
|
|
Different namespace? Different project? Form2 already compiled?
|
|
|
|
|
Form2 is already Added to the Project.
Code file Global.cs and Namespace Globals
And in that file I want a common procedure that I can use on any form in my App.
Hope this helps.
- Stop thinking in terms of limitations and start thinking in terms of possibilities -
|
|
|
|
|
Are the Global class and the Form2 class both in the same namespace? Namespaces or reference errors could do that. Sadly without any further information the exact cause would continue to remain obscure to most non-clairvoyants. Another piece of possibly unwanted advice from me would be to avoid at all costs any type of "God Object" global type poison in your code, and please use appropriately named types.
Need more info.
Scott
"Run for your life from any man who tells you that money is evil. That sentence is the leper's bell of an approaching looter." --Ayn Rand
|
|
|
|
|
Thanks Scott, I had a spelling mistake in namespace
- Stop thinking in terms of limitations and start thinking in terms of possibilities -
|
|
|
|
|
Out of curiosity, which IDE/editor are you using?
"Run for your life from any man who tells you that money is evil. That sentence is the leper's bell of an approaching looter." --Ayn Rand
|
|
|
|
|
carbon_golem wrote: Another piece of possibly unwanted advice from me would be to avoid at all costs any type of "God Object" global type poison in your code, and please use appropriately named types.
Why is this bad?, Because of hackers etc? or...
Regards,
Gareth.
|
|
|
|
|
gareth111 wrote: Why is this bad?, Because of hackers etc? or...
No, not because of hackers. You don't do this because it's horribly bad design. There might be people comming in behind you that get stuck maintaining your code, and, after seeing this, might want to hunt you down and throw you into a vat of boiling lead.
|
|
|
|
|
I should have given a reason for that...
OOP has a few important best-practices guidelines that usually appears in the beginning of text books that sadly are forgotten by the end of them.
Objects should hide data, encapsulate data, and ensure data integrity to name a few. Objects serve a function of providing a structure around important data and work with other Objects to support a few inter-object relationships. (Is-A:association and Has-A:inheritance) Objects should also be coherent meaning if your problem calls for a Person and Pet, you would want to construct Person and Pet classes, and not put them into one 'God Object'. Global objects are not resistant to change either.
I hope you're starting to see the reasoning for this. If you have a library with Person, and Pet classes, you don't have to write them again for one, but now the program is coherent when read.
Tomes upon tomes have been written on the subject. I have given you a barely-adequate explanation, so I strongly recommend getting a book on object oriented programming, it's not just a bunch of fluff, it will save you effort bigtime.
Scott
"Run for your life from any man who tells you that money is evil. That sentence is the leper's bell of an approaching looter." --Ayn Rand
|
|
|
|
|
If you're doing this, it's an indication of bad design, violating OOP rules for encapsulation. Why would your "Global" class need to know anything about a form, or the controls on it? Hint: In proper design - the "Global" class shouldn't know or care about anything else outside of itself.
If you want to send data and status information back to Form2, the Globals class should expose events or delegates that an instance of Form2 should subscribe to to get notification of these things.
|
|
|
|
|
Thanks for that Dave.
Regards,
Gareth.
|
|
|
|