Deselecting RadioButton

I can have a set of RadioButtons, all not selected.
When I click one of them it gets selected and if I click another, the new one is selected and the old one is deselected.
As far as good.

But is it possible to deselect them all? For example if I made a mistake and I want not to have anyone selected.
When I click a selected one it doesn’t get deselected. So, it seems it is not possible.

I’ve been thinking in asking a new feature, but I’d like to know if someone would find it useful.

rb(index).value=false

assuming you have them in a control set (which if you don’t you should)

Thanks Dave, but it is not so simple. At least for me.

First of all you must decide the event to manipulate. Normally I would take the event Action.
But in this event, the radiobutton value is always true. No matter which was the previous state.
Therefore I can not use

rb(index).value=false

I’m trying with a simple case (empty window with two radiobuttons) and I get this:
If I use MouseDown event with;

me.value = not me.value

it works only if I make the mouseUp out of the radiobutton.
If I write

me.value = not me.value Return True
it works very well, but I have to move the code from the Action event to the MouseDown event, since it only goes to the Action event if the final value is True.

So, it seems I have a workaround, but I would prefer the possibility to use only the Action event which is the one to be used.

if you want them to “toggle” (which is not what I got from your OP), then use CHECKBOXES not RADIOBUTTONS
you can easily add code to a checkbox control set to insure only ONE is set at a time

[quote=273478:@Ramon SASTRE]I can have a set of RadioButtons, all not selected.
When I click one of them it gets selected and if I click another, the new one is selected and the old one is deselected.
As far as good.

But is it possible to deselect them all? For example if I made a mistake and I want not to have anyone selected.
When I click a selected one it doesn’t get deselected. So, it seems it is not possible.

I’ve been thinking in asking a new feature, but I’d like to know if someone would find it useful.[/quote]

Thats a non-standard behaviour for a set of radio buttons which by definition, SHOULD have one selected at all times.
It would/could be argued that at least one should be selected by default at window open and that one isn’t is a bug.
You should use check boxes which permit you to have as many selected at a time you want.
And, sa Dave noted, it is easy to make a set that only has one selected at a time but can have none selected.

Thanks Norman.
I know that this is not a normal behaviour, and I never said it was a bug. I talked about a new feature.
I can’t use check boxes because I don’t want to have as many selected as you want.
What I need in my case is “one” or “none”

One solution is adding a new radiobutton with caption “None” :wink:

A tiny bit of code can make that work for a set of check boxes
Or add one radio button that is “none of the above”

I’m still unsure why either of the approaches I have mentioned cannot be made to work for you?

  • You want a number of radio/checkboxes
  • If you click an already selected one, it becomes UNSELECTED
  • if you click one that is NOT already selected, IT becomes selected, and any other selected ones become unselecte

this is standard radio behaviour, except for bullet #2
this is standard checkbox behaviour except for bullet #3

and it is easy to make either check/radio to adhere to all 3 bullets

If this is what you are after, I’m willing to make a simple project that you can use as a template…
just tell me if you want it based on Radio or Checkboxes…

I think this is more of a feature for your application, as opposed as a widely used feature. This can be done with checkboxes dead easy with some code. And there were some controls out there that looked like a radio button, but were more like circular checkboxes that may be more visually appealing to you.

[quote=273478:@Ramon SASTRE]I can have a set of RadioButtons, all not selected.
When I click one of them it gets selected and if I click another, the new one is selected and the old one is deselected.
As far as good.

But is it possible to deselect them all? For example if I made a mistake and I want not to have anyone selected.
When I click a selected one it doesn’t get deselected. So, it seems it is not possible.

I’ve been thinking in asking a new feature, but I’d like to know if someone would find it useful.[/quote]

How would a user select the “none” option if there’s no button labelled “none” ?

I know that I can do (as Norman says) a bit of code with check boxes.
But I prefer the “None” option, because users know that check boxes can be checked independently.

And I agree with Lange that this would not be widely used, so I must solve my case and forget about it.

Dave, thanks again, but don’t worry. All this conversation has been very useful for me.

Thanks to all.

I am not expert but why not checkboxes with a global property with default integer and select case?
Depends of how much checkboxes do you want put them in the property and use the select case

select case "Global Property" case 1 to 2 "do this" case 2 to 4 "do that" end select
etc

SUB ACTION(index as Integer)
dim i as integer
for i=0 to 5 // 5 is example, depends on how many buttons you have
if i=index then continue // skip the button we just clicked
me(i).value=false // turn it off
next i
me(index).value=not me(index).value // toggle the one we did click
END SUB

off the top of my head, so might not be 100% accurate :slight_smile:

You can have a select none by hiding one of the members.

Then when you set the hidden one value true, none visible is selected.

Only trouble is the could UI start with none selected and the user interacting with that UI has NO way to return to that state (ie/ to return to “none” selected)

So once you make a choice you’re stuck with it

When this is the case you often see

     [X] Use one of 
               o choice one        o choice two       o choice three

OR

               o none       o choice one        o choice two       o choice three

So the user can indicate “none of the above” or return to the “no choice made” configuration