Главная страница | назад





Article #17043: How do I use TRadioGroup?

 Question and Answer Database
FAQ2043C.txt How do I use TRadioGroup?
Category :VCL
Platform :All
Product :C++Builder 3.x
Question:
I know this sounds like a dumb question, but how do I use the
TRadioGroup? I put one down and then place TRadioButtons on
top of it, but it still groups the radio buttons to the form
not the radio group.
Answer:
Chances are this user really wants to be using a TGroupBox
To use the TRadioGroup you have to add the RadioButtons to the
Group using the Items property of the
TRadioGroup. The selected Radio button is the one that is
indexed in the ItemIndex property of the RadioGroup. Following
is a snippet of code that illustrates the correct way to use the
TRadioGroup:
void __fastcall TForm1::FormCreate(TObject *Sender)
{
RadioGroup1->Items->Add("Tara Martin");
RadioGroup1->Items->Add("Austin Powers");
RadioGroup1->ItemIndex = 2;
}
void __fastcall TForm1::RadioGroup1Click(TObject *Sender)
{
if (RadioGroup1->Items->Strings[RadioGroup1->ItemIndex] == "Tara Martin")
ShowMessage ("Tara Martin is selected");
else
ShowMessage ("Austin Powers is selected");
}
5/18/98 8:50:41 AM

Last Modified: 01-SEP-99