02-15-2011 04:44 AM
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
Solved! Go to Solution.
02-15-2011 04:58 AM - edited 02-15-2011 05:02 AM
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:
If you don't want to use this instrument, implementing a radio group is rather simple. You can use something like this:
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
}
02-15-2011 05:00 AM
Here the radio button example :
http://zone.ni.com/devzone/cda/epd/p/id/4118
02-17-2011 03:26 AM
Thanks you very much. This solve my problem.
--Vishnu
02-22-2011 01:23 AM
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
02-22-2011 01:32 AM
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.
02-22-2011 12:36 PM
Try turning the tree attribute ATTR_RADIO_SIBLING_ALWAYS_MARKED off...
SetCtrlAttribute(panelHandle, PANEL_RADIOGROUP, ATTR_RADIO_SIBLING_ALWAYS_MARKED, 0);
02-22-2011 01:40 PM
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
02-23-2011 08:03 PM
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.
02-23-2011 10:15 PM
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