[Newbie alert!]Radio Button within a groupbox

  • Thread starter Thread starter kohoutec
  • Start date Start date
K

kohoutec

Hi all

Sorry, this is a rather basic question :-) In C++ Builder its possible to
create a "Radiogroup" and populate it with radiobuttons, these then have
their own index within the group. In my case I want to use this
"itemindex" in a switch statement, ie

switch(RadioGroup->ItemIndex)
{
case 0: //do stuff
break;
etc
}

I'm trying to find a way to do the same sort of thing in c# but am not
having much success and wondered if anyone can suggest an easy way to do
this. I should point out my knowledge of c++/c# is pretty basic so speak
slowly :-)

Many Thanks
Jon
 
Hi kohoutec,

I'm also from a C++ background, so I looked for a way to handle radio
buttons with a switch statement, and discovered that you can't do it in C#.
In C# you don't access the radio buttons as a group, you just access each one
individually, and you use the Checked property to find which one is is
selected.

eg. There are two radio buttons, radioButton1 and radioButton2. To find
which one is set, you go...

if (radioButton1.Checked)
{
handle radio button 1
}
else if (radioButton2.Checked)
{
handle radio button 2
}

(yes, the second conditional is redundant, but I put it in there anyway, for
symetry)

HTH,

Javaman
 
Thanks Javaman - thats what I ended up doing as it happens, it just seemed
a little clunky at the time as I have 5 radio buttons, but its nice to
know I wasnt missing something obvious :)
 
Back
Top