Binding a dynamic property to the text of a radio button

Hi Guys,
I have a dynamic property on the root container called BBT that is a string. I have a container on the window with about 20 differnet radio buttons in it for the user to select the correct BBT. Is there a slick way to bind the text value of the selected radio button to my dynamic property?

Hmm…not really. The ‘slickest’ way I can think of is this, and its not that elegant:

Name your radio buttons “XYZ1”, “XYZ2”, “XYZ3”, etc (Replace XYZ with something meaningful, of course)

Create an integer dynamic property called “SelectedRadio”, and bind it to an expression like this:

binEnum({Root Container.XYZ1.selected}, {Root Container.XYZ2.selected}, ...)

(Tip - you can rename the root container to “rc” or something to shorten up your binding paths)

This way, the “SelectedRadio” button will contain a number from 1-20 indicating which radio button is selected. Then bind BBT to:

switch({Root Container.SelectedRadio}, 1,2,3,...,19,20, {Root Container.XYZ1.text}, {Root Container.XYZ2.text}, {Root Container.XYZ3.text}, ... {Root Container.XYZ19.text}, {Root Container.XYZ20.text}, "Select Something")

To make this easier - don’t use radio boxes - use a List with 20 entries set to single selection mode, and see which one they select.

Hope this helps,

Thanks Carl. I’ll give this a shot. The list is a better option, but I am using PMI to replace an existing MS Access application and was trying to make all the input screens appear the same as the old version.

Yeah, I understand where you’re coming from. The binding I described above will work great, it just takes a bit to set up.

I think I may have a suggestion.

Try this:

  1. Add a dynamic property to the root container of your window. Give it a name like “SelectedValue”.
  2. Place your first radio button on your window.
  3. Change any nominal properties (e.g., Text)
  4. Give it a dynamic property called “Value” and set its value to something unique.
  5. Right-click the radio button and select Configure Actions
  6. Navigate to Action, Action Performed and then select the Script Editor tab. Enter “event.source.parent.SelectedValue = event.source.Value”.
  7. Duplicate the radio button and customize its properties as many times as you need. Make sure you give each radio button’s “Value” property a unique value.

If it’s set up correctly (and I’ve explained it correctly), when you click on a radio button, the window’s “SelectedValue” property will reflect the currently selected radio button “Value” property. You can then drive other scripts/actions based on this value.

BTW, you don’t have to use a window dynamic property like “SelectedValue”, but you could also update some other object’s property directly. Nor do you have to use a custom property of the radio button. You could use the Text property directly. Just make the appropriate changes to the Action, ActionPerformed script to use the desired properties.

Please let me know if this works for you.

That’s a great idea MickeyBob! You can even take it one step further and make those “value” and “selectedValue” properties into strings and bind the “value” property to the text of the radio button. That way Ron can get exactly what he was asking for.

For simplicities sake, I would put all these radio buttons in a container and put that selectedValue property on that and not the root container. I have found that the more self contained each section of the project is, the easier it is for someone else (or yourself!) to figure out what you were doing.

Yeah, I usually don’t condone doing in scripting what can be done in binding - but in this case its probably a fair toss-up because the binding version isn’t very intuitive.

FYI - your script should be on the item > itemStateChanged event, and should look like this:

if event.stateChange == event.SELECTED: event.source.parent.SelectedValue = event.source.Value

This event is more in line with how the radio button works than the actionPerformed event.

Thanks guys. Pretty cool way of handling this.