Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loop Through items on group box?

Status
Not open for further replies.

Wings

Programmer
Feb 14, 2002
247
US
Hi,
I need to write a while loop to address a large number of
checkboxes on a groupbox. The checkboxes are named sequentially eg: CheckBox1, Checkbox2

How do I access the names individually?

I know i need a counter

but I cant go

if (CheckBox + Counter ->checked == true)

Any help would be appreciated
 
Hi,
wanna do this?

for (int i=0; i<GroupBox1->ControlCount ; i++)
if (GroupBox1->Controls->ClassNameIs(&quot;TCheckBox&quot;))
if(((TPanel *)GroupBox1->Controls)->Checked)
DoBlaBla

CU Stummel
 
That almost works except that I get the error message
&quot;checked is not a member of TControl&quot;
This is true, and unfortunately csChecked is not viable so I can't use the control state property either.

Any Ideas?
 
How about allocating an array of pointers to 'Checked' and setting the array at start, it could be one major typing job at first but then it's possible to index and such. I have not tested it but just got the idea and wanted to share it with you.
 
Sorry, wrong cast - i should try it before posting :) and now with code tags :)

Code:
for (int i=0; i<GroupBox1->ControlCount ; i++)
 if (GroupBox1->Controls[i]->ClassNameIs(&quot;TRadioButton&quot;))
   if(((TRadioButton *)GroupBox1->Controls[i])->Checked)
     RichEdit1->Lines->Add(((TRadioButton *)     
                        GroupBox1->Controls[i])->Name);

Stummel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top