LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

how to group radio buttons in LabWindows/CVI

Solved!
Go to solution

Hi all,

    I am using 3-radio buttons in my GUI. Where only onle is selected at a time or no one is selected. For example I have Three buttons B1,B2 and  B3. By default B2 is selected and (1) if i press B2 it self, it will deselect and no one is selected in this group. (2)If B2 is allready selected and i press B1, then B2 will deselect and B1 will be selected.

 

 

Is there any why to group multiple radio buttons?

 

--Vishnu

0 Kudos
Message 1 of 15
(7,582 Views)
Solution
Accepted by Vkumar

Hi Vishnu,

CVI comes with a custom control called Radio Group that you can use for this purpose. It is basically a customized tree control that you can add to a panel. You can locate this control among Toolslib controls:

 

Radio group.PNG

 

 

If you don't want to use this instrument, implementing a radio group is rather simple. You can use something like this:

 

  1. Create controls that must be grouped on the panel
  2. Create an array of controls
         int  ctl[3];
         ctl[0] = PANEL_RADIOBUTTON1;
         ctl[1] = PANEL_RADIOBUTTON2;
         ctl[3] = PANEL_RADIOBUTTON3;
  3. In the control callback:
         for (i = 0; i < 3; i++) SetCtrlVal (panelHandle, ctl[i], 0);    // Turn off all controls
         SetCtrlVal (panelHandle, control, 1);     // Turn on active radio button

Edit Normal behaviour in radio buttons is that one element in the group should be always selected. If you want to have the ability to have no controls selected at all you can easily customize step 3 to obtain it:

     for (i = 0; i < 3; i++) {
         if (control |= ctl[i]) SetCtrlVal (panelHandle, ctl[i], 0);    // Turn off all controls different from the active one
     }



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 2 of 15
(7,578 Views)

Here the radio button example :

 

http://zone.ni.com/devzone/cda/epd/p/id/4118

-----------------------------------------
Kobi Kalif
Software Engineer

0 Kudos
Message 3 of 15
(7,578 Views)

Thanks you very much. This solve my problem.

 

--Vishnu

0 Kudos
Message 4 of 15
(7,527 Views)

Hi,

    I have use Radio Group. It is working fine. Is there any way to deselect any option programmically. For example, option1 is selected and if i press option2 then option1 is deselect and option2 is selected.. But now is option2 is selected and i press again option2, option2 should be deselect and other options(0 or 1) should not be selected. Means all options are unselected.

 

I have searched in help. There is a command for selection (Radio_SetMarkedOption) but not for remove selection.

 

--Vishnu

0 Kudos
Message 5 of 15
(7,479 Views)

To my understanding, a 'radio button group' means that one and only one selection is possible, not zero, not two.

 

If you want a different functionality, you can use individual control elements, where any combination is permitted.

0 Kudos
Message 6 of 15
(7,478 Views)

Try turning the tree attribute ATTR_RADIO_SIBLING_ALWAYS_MARKED off...

 

SetCtrlAttribute(panelHandle, PANEL_RADIOGROUP, ATTR_RADIO_SIBLING_ALWAYS_MARKED, 0);

 

 

0 Kudos
Message 7 of 15
(7,464 Views)

Ah, that's interesting... According to the help this control attribute is valid for trees (only). And indeed, the radio group control is a tree, I wasn't aware of this.

 

Thanks, jared

0 Kudos
Message 8 of 15
(7,453 Views)

Here's an example how you can implement a radio button group using a control array. The radio group custom control is based on a tree control, so the options have to be spaced vertically. If you need a radio button group spaced differently, you can use the API provided by the attached files (radioBG.c and radioBG.h). It also provides an attribute (ATTR_ALLOW_DESELECT) that allows the selected radio button in the group to be deselected when it is clicked on, leaving all the radio buttons unselected.

0 Kudos
Message 9 of 15
(7,417 Views)

Dear Jared,

        When i run your program in my CVI2009, There are "Missing prototy error" in radioBG.c for

GetCtrlArrayPanel,  GetNumCtrlArrayIterms, GetCtrlArrayIterm, ....etc

and same for radioGroupCtrlArray.c

GetCtrlArrayFromResourceID,

 

Do i need to include any header file for this?

 

--Vishnu

0 Kudos
Message 10 of 15
(7,410 Views)