groupbox and radio buttons

Hi All.

Sorry for asking this stupid question, but I can’t seem to figure something out even after reading through “Introduction to xojo”.

I have 3 radio buttons within a group box.

I want to pop up a message box saying “You pressed radio button 1, 2, 3” thing, but I can’t seem to find the right syntax.

Can someone show me how to do this. I know the groupbox becomes a parent, but I just can’t get it to work.


inside the ACTION event , check the INDEX value, it will be associated with the radiobutton pushed

Hi Dave.

I’m really doing something stupid.

I have my 3 radiobuttons within a Groupbox.

In the action event for the radio buttons, just for now, I am asking it to print out the radiobutton1.index, and it throws this massive number : -21799xxx

Under the radiobutton Action event, if I use Groupbox1.index I get the same thing

If I use radiobutton1.value I get True or False.

I’m confused.


The action event should return an index variable

ACTION(index as integer)
msgbox "You pressed radiobutton #"+str(index)

groupbox1.index is the index within a controlset (which you should be using) but if not, it does return that huge neg number (by design)

Radiobuttons that are in a group box (or similar parent) act as a group. Implement the action event in each RadioButton and just use this code:

Msgbox "This is radioButton <X>"

Dave’s reply was assuming your were creating Control Set (sometimes called a Control Array). In that case the index (of the control group) would be passed in via the Action event.

But if you are unfammiliar with the concept of Control Arrays, … :slight_smile:

@Michael Cebasek you can add a RadioButton, give it a Name. Then add another RadioButton and give it the same Name, Xojo will ask if you want to create a Controll Array. Now you can Add more RadioButtons with the same Name and they will be added to your Control Array also.

Now you have to deal with one Action Event for all Controls in the same Control Array. In this Action Event you have an index Property which tells you which Control in this Array has been used. Now @Dave S 's example will work.

radio buttons depend on their parenting to know which ones should act as a group of related radio buttons
in a related set when you click one to enable it the others will disable
and this has nothing to do with them being a control set

if you have a control set of two radio buttons and a single radio button that is not part of the control set on a window all three behave as a single group of radio buttons
click any one and the others will disable

to make it so they act as independent groups you need to parent the ones you want to act as one set in a canvas or other control and the rest in something else

and you could split a control set across those containers

And i always hoped this would be changed someday. :slight_smile:

But until then, we can achive this with our own code :slight_smile:

why do in code what you can do just by putting them inside a canvas that is invisible ?

Thanks all.

This is beginning to come back to me. I worked with RealStudio for a long time, but been away longer. Now the light is beginning to come back on.

Thanks for your help guys. Though I will probably have more questions.