How to create Radio Button in UI by code

Hello everyone,

I have a problem want to help. Ex:


I have a list 4 item like image. I want to make the radio button in UI by code when Window load.

How i can do this with xojo, or any solution to do this, can you suggest to me.

I read any document of radio button but I don’t see document how to create UI Item by code.

You cannot create a radio button on screen if one does not exist already.
Some people create a window with the maxmimum number of radio buttons they would ever need, and make most of them visible = false at first.
Then make as many as they need visible afterwards

The other way to to do it is to add one radio button in the IDE,
Then go to the inspector, and set ‘member of’ to say ‘new control set’
Now, the control has an index number.

Say it is called MyRadio
And at run time you need another 3 of them
You do it in code something like this

dim r as MyRadio
dim t as integer = MyRadio.top   //may need to be MyRadio(0) .. this is untested code
for x as integer = 0 to 2
r = new MyRadio
r.top = t + MyRadio(0).height + 30   //set the top position relative to the last one
r.left = MyRadio(0).left  //set the left position relative to the last one
r.caption = "Clone " + x.totext   // or format(x,"0") in api 1
t = r.top //update our vertical position monitor
next

If there is a possibility that the list would be too big for the screen, you may prefer to use a listbox with single row selection.

1 Like

Thanks you Jeff,
I will try it now, and let you know my result.

Or place one radio button on a Container, then embed an array of these Containers. You will have to manage their Value.

1 Like

Thanks you David, I will try

Hi Jeff,
This work perfect, So like you say, I have more than three item, so that my layout was break out side.
However in my case, I can’t use Listbox, because can use listbox everything was easy.
Can we use something may make scrollable, or same?

Why?

There is little difference between a listbox where one row can be selected, and a list of scrolling radio buttons.
But the user will be more familiar with a listbox.

1 Like