Radio Button set

(Probably a silly question)

A radio button set is placed on an additional window (addWindow).
From the main window I want to know whichone one is selected.
One way is to declare a property in the addWindow that keeps the radio button index selected.
Another one is from the main window loop on each member and check if its value=true

But…, there is not a more elegant way to know which element is selected in the radio button array?, like mySet.SelectedRowIndex?

Place a Property in a Module and fill it in the RadioButton (in Action), then check that Property to know who is True.

Thanks Emile, this was the used system but, is not a way like?… For example those used in a segmentButton?

SegmentedButton1.SelectedSegmentIndex

It seems silly to have to create a property to keep something that is already in the object set itself.

[quote=488131:@Enric Herrera]Thanks Emile, this was the used system but, is not a way like?… For example those used in a segmentButton?

SegmentedButton1.SelectedSegmentIndex

It seems silly to have to create a property to keep something that is already in the object set itself.[/quote]
A segmented button is a single control. It can hold its value internally (e.g. as an integer).

But a radio button set is not: each button is a different object.
Consider any array of objects (of any given type): if you want to know which of your objects has a given property set to, e.g. 13, you must either loop thru the array and find the object, or set a specific “global” value earlier, when you change the property.

You can make the “magic” yourself by having a method returns the pressed button, but since each radio button will always be different objects, there’s no “parent object” in the OS which will do that for you (and this would be about the same function you should do anyway).

Thanks Arnaud, I assumed (wrongly as I see know) the set should be like a super class or a parent that keeps order of the members.

Well, you were not wrong, only the information isn’t available in Xojo. My answer targeted what we have inside Xojo. At the OS level, there’s indeed “something” that keeps track of radio buttons groups, so that if you select one, the others are deselected.

Xojo doesn’t provide that information for us. Also, I checked in Apple documentation and didn’t come with useful answers. That’s a real mess: NSMatrix was the way up to 10.7 and now NSButton styles are all marked as deprecated; I couldn’t find the current implementation.

I wanted to search whether there’s a direct way to get the currently selected radio button (an API) but didn’t find anything; it’s possible the OS handles that but keeps its work internally.
And this would, of course, be different on Windows and Linux.

I’ll keep searching, but wanted to provide an “intermediate” answer for now.

Update: I found this call: NSControlMBS.selectedCell which would be a good candidate. Would you be OK with a plugin way?

[quote=488376:@Arnaud Nicolet]Well, you were not wrong, only the information isn’t available in Xojo. My answer targeted what we have inside Xojo. At the OS level, there’s indeed “something” that keeps track of radio buttons groups, so that if you select one, the others are deselected.

Xojo doesn’t provide that information for us. Also, I checked in Apple documentation and didn’t come with useful answers. That’s a real mess: NSMatrix was the way up to 10.7 and now NSButton styles are all marked as deprecated; I couldn’t find the current implementation.

I wanted to search whether there’s a direct way to get the currently selected radio button (an API) but didn’t find anything; it’s possible the OS handles that but keeps its work internally.
And this would, of course, be different on Windows and Linux.

I’ll keep searching, but wanted to provide an “intermediate” answer for now.

Update: I found this call: NSControlMBS.selectedCell which would be a good candidate. Would you be OK with a plugin way?[/quote]
Which plugin? Sorry for my ignorance.
In fact is not so complicated to add a property and keep this info, I was just wondering why is not provided by Xojo.

In this case, it would be the MBS plugin. Since you’re asking, I guess you don’t have it (and it’s not a free one).

This is something handled by the OS, and probably differently in each OS. It’s also fairly possible some systems don’t provide an API to directly get the selected button in a radio group. The final decision is Xojo’s one.

A feature request could be appropriate.

Ah, thank you, as I develop not for comercial use I do not buy plugins that are not free.

Radio buttons are grouped by their Parent control. You can have radio buttons in a control set that function as separate groups, simply by putting them on different parent controls. And you can have radio buttons that are not in a control set in a single group, by putting them on the same parent. The name of the control is not what makes it a functional group.

Your best approach is to maintain a property on the window to indicate the current status of the radio buttons.