Radio Group

Xojo Version 2021 r3.1

Description:

Radio Groups are used when you want the user to select only one option from a group of options. Radio Groups should be placed inside of a group box.

Library Location:

Radio Groups are found in the Pickers category in the Xojo Library

Naming Conventions:

The prefix for a Radio Group is: rad

Adding a Radio Group to your form:

  • Place a Group Box on onto your Form and give it a name (Remember to follow our naming conventions)
  • Place a Radio Group inside of the Group Box and give it a name (Remember to follow our naming conventions)
  • In the Layout View, hover over the Radio Group and the edit icon will appear
  • Click the edit icon to add/edit the options
Radio Group Options
Setting Radio Group Options

Accessing the Selected Item from a Radio Group

The SelectedItem method tells us which option in a Radio Group is selected allowing us to access it's properties. In the example below we access the value of the Caption property and set it equal to a variable.

myVariable = radGroupName.SelectedItem.Caption 

Radio Groups and If/Else If Statements

We can use an If/ElseIf statement to test the value of the SelectedItem's caption and run related program statements.

If (radColor.SelectedItem.Caption = "Red") then
 lstOut.AddRow("You selected red") 
elseIf (radColor.SelectedItem.Caption = "Blue") then
 lstOut.AddRow("You selected blue") 
elseIf (radColor.SelectedItem.Caption = "Purple") then
 lstOut.AddRow("You selected purple") 
elseIF (radColor.SelectedItem.Caption = "Green") then
 lstOut.AddRow("You selected green") 
End If