Dynamic RadioButton Creation

Platform: Linux - Kubuntu 24.04
Let the image show the problem… I took the code straight from the documentation and only changed what I want to see.

If you want to show code copy and paste it in, highlight it and press the </> button. It’s so much easier to read. What page in the documentation did you get the code from?

Looking at the code it is suggesting that DesktopRadioButton doesn’t have a constructor that takes just one string. According to the Docs it does offer one, not sure why that wouldn’t work.

I guess the docs are wrong. The docs says it can receive a caption in the constructor, but the compiler says: “no”.

1 Like

I chose the image method so it shows the errors as well.

It doesn’t seem to take two parameters either.

Var aButton As New DesktopRadioButton( "Hello", True )

Fails in the same way. Add a bug report against the documentation?

Web claims to have a similar constructor, perhaps they either thought of adding it and didn’t or copied the documentation from the web version and forgot to remove it?

This works in Web:

me.RemoveAllRows

me.AddAt(0, new WebRadiobutton("Test1"))
me.AddAt(1, new WebRadiobutton("Test2"))
me.AddAt(2, new WebRadiobutton("Test3"))
me.AddAt(3, new WebRadiobutton("Test4"))

Note: RemoveAllRows instead of RemoveAll for Desktop

The above code needs to be changed to:

me.RemoveAll

Var rb As New DesktopRadioButton
Var rb1 As New DesktopRadioButton
Var rb2 As New DesktopRadioButton
Var rb3 As New DesktopRadioButton
rb.Caption = "Test1"
me.AddAt(0,  rb)
rb1.Caption = "Test2"
me.AddAt(1,  rb1)
rb2.Caption = "Test3"
me.AddAt(2,  rb2)
rb3.Caption = "Test4"
me.AddAt(3,  rb3)

to make it work in Desktop.

Note: both say ‘Selected Index 0’ under Behavior but just Web shows the first item (number 0) selected.

Xojo should make Desktop work like Web, no?

I don’t think you can just add your own constructor to UI classes. You can however, create a subclass and add the constructor to that.

Thank you, that seems to work just fine!

So is this a web project? If so then part of the problem is you were trying to add a DesktopRadioButton to a Web Application.

If it is a Desktop application then I’m baffled that you would be able to add a WebRadioButton to a Desktop app.

Nope, I don’t do web stuff. Only desktop. I was using the DeskTopRadioButton, the other fellow, Alberto, was using the WebRadioButton.

Strange that you quote the web code from my post saying that it works just fine. So I’m confused.

Then adding a WebRadioButton to a DesktopRadioGroup shouldn’t work. I’m stunned that it does.

I wouldn’t recommend mixing the two, even if it does work.

It doesn’t:

Then I don’t understand, this at all?

1 Like

I just replied and the site grabbed whatever. Okay, so I went and looked back and reply that seems to have everyone confused is actually not that mysterious. In Alberto’s response to me he posted both web and desktop. His web response was at the top and the desktop portion below. What worked was the desktop portion, but I replied to his post to acknowledge his desktop solution… see below, worked.

' ----> Variables <----
Var rBtn01 As New DesktopRadioButton
Var rBtn02 As New DesktopRadioButton
Var rBtn03 As New DesktopRadioButton
Var rBtn04 As New DesktopRadioButton
Var rBtn05 As New DesktopRadioButton
Var rBtn06 As New DesktopRadioButton
Var rBtn07 As New DesktopRadioButton
Var rBtn08 As New DesktopRadioButton
Var rBtn09 As New DesktopRadioButton
Var rBtn10 As New DesktopRadioButton

' ----> Preliminary Code <----
Me.RemoveAll

' ----> Main Code <----
Select Case frmMaster.cboDaily.Text
Case "Groceries"
  rBtn01.Caption = "Dollar General"
  Me.AddAt( 0, rBtn01 )
  rBtn02.Caption = "Safeway"
  Me.AddAt( 1, rBtn02 )
  rBtn03.Caption = "SaveMart"
  Me.AddAt( 2, rBtn03 )
  rBtn04.Caption = "WalMart"
  Me.AddAt( 3, rBtn04 )
  
Case "Dining Out"
  rBtn01.Caption = "The Willow Wisp"
  Me.AddAt( 0, rBtn01 )
  rBtn02.Caption = "BeWok Japanese"
  Me.AddAt( 1, rBtn02 )
  rBtn03.Caption = "Pizza Plus"
  Me.AddAt( 2, rBtn03 )
  rBtn04.Caption = "Mongolian BBQ"
  Me.AddAt( 3, rBtn04 )
  rBtn05.Caption = "McDonald's"
  Me.AddAt( 4, rBtn05 )
  
Case "Entertainment"
  
End Select

Me.SelectedIndex = -1

The web stuff, I never even tried it… because I don’t do web stuff.

1 Like

So the confusion is that the quoting mechanism hid everything apart from the WebRadioButton elements, thus the confusion. I’ve only just noticed the arrow that allows you to see more.

Just a note. When quoting you can start a reply and then highlight part of a post and click the button that shows to quote just that part. It helps with clarity and makes things shorter. Both helpful.

Glad you get what you needed.