LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to make a horizontal Radio Group?

Solved!
Go to solution

Hi,

    My problem is that I want to make a horizontal radio group. I am unable to make a horizontal group. CVI only allows me to make a vertical radio group. I need help to make a horizontal radio group. Thank you in advance to anyone who can help me out in this.

 

Regards,

Farhan.

Regards,
Farhan Ahmad.
0 Kudos
Message 1 of 12
(7,080 Views)
Solution
Accepted by topic author lahorimunda

CVI does not have a native horizontal radio group control. The toolbox radio group control is developed on top of a tree control, and this is why it has a vertical extension. As you have noted, there is no way of changing its appearance.

 

Nevertheless, you can mimic a radio group control by using a set of radio buttons and a few lines of code. I have made a small example to help you develop such a layout: note the use of an array of control IDs to simplificate coding.



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 12
(7,077 Views)

Farhan:

 

You can create the radio button group yourself in code, the way we needed to before radioGroup.fp.

 

Place individual Option buttons on your UIR, in whatever arrangement you want (vertical, horizontal, diagonal, etc.).

Assign the same callback name to all option buttons that will be in your radio group.

In the callback, set the value of the clicked control to TRUE, set the others to FALSE.  This is easy if you put all the buttons in your group into an array.

 

See the attached example.

 

EDITED NOTE: Roberto beat me to it.

Message Edited by Al S on 11-09-2009 05:44 PM
Message 3 of 12
(7,079 Views)

@Al 

I looked at your solution: may we be twins separated immediately after birth? Smiley Very Happy Smiley Very Happy



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 4 of 12
(7,075 Views)

Roberto:

 

Yeah, that was pretty embarrassing.  I didn't add much value there.  But twins?  I have never been able to grow a beard.

0 Kudos
Message 5 of 12
(7,059 Views)

Hi,

   Thank you guys for helping me out here. I had to select the first one as the accepted solution although both are the same. Thank you to both of you for helping me out.

 

Regards,

Farhan.

Regards,
Farhan Ahmad.
0 Kudos
Message 6 of 12
(7,049 Views)

Hi again,

            Need a little more help from you guys. I am using the radio group in another callback Function which is basically a reset callback function. When I use the code in that call back function it does not allow me to use control and gives me an error for sts that it is expecting a char instead of an int. What should be the control in the case when I am using it in another callback function? I was having the problem that when I had one of the radio buttons selected and pressed the reset I get two of them selected at the same time. Then I tried to put the

 

Regards,
Farhan.

Regards,
Farhan Ahmad.
0 Kudos
Message 7 of 12
(7,017 Views)

Fahran:

 

The control parameter passed to any callback function is the control that generated the event.  If you want to reference another control, you need to refer to it by the control ID that's in the .h file for your UIR.

 

For example, look at the following function definition for the callback assigned to an OK button.

int CVICALLBACK OKCallback (int panel, int control, int event,

void *callbackData, int eventData1, int eventData2)

 

In this case,  control refers to the OK button.  But in that function you can still reference any other control using the format PANELID_CONTROLID.

 

Usually when you get an error referencing a control expecting one type and getting another, it's because you're referencing the wrong control or the wrong panel (if you have more than one), not the one you think you are.

 

An easy way to make sure you're referencing the right control in CVI control functions (e.g. GetCtrlVal, SetCtrlVal) is to use the function panel for the CVI function, click in the box for the control ID, and press Enter.  A list of control IDs will show up for you to select from. 

 

To search for a function panel, in any code window press Shift-Ctrl-P and enter any part of the function name.  To call up the function panel for an existing line of code, click on the function name in your code and press Ctrl-P.

 

If this doesn't help, can you post the code in question? 

0 Kudos
Message 8 of 12
(7,004 Views)

Hi,

    Thanks for your Help. I have attached the program I am having problem with. When you press the reset button after you have selected any other option than option 1, two options get selected.

 

Regards,
Farhan Ahmad.
0 Kudos
Message 9 of 12
(6,961 Views)

Farhan:

 

Just remember that you built the radio group in code which gets run when one of the buttons in the group generates a commit event.

 

When you set a control's value using SetCtrlVal(), a commit event is not generated, so when you press the Reset button, you don't call the code that clears the inactive buttons.

 

Try this in your reset function.

 

int CVICALLBACK Reset (int panel, int control, int event,
  void *callbackData, int eventData1, int eventData2)
{
 int i;
 switch (event)
 {
  case EVENT_COMMIT:
   // Preset initial element of the radio group
   SetCtrlVal (panelHandle, PANEL_OPT1, 1);
   
   // Deselect all other elements in the group
   for (i = 1; i < 4; i++)
    SetCtrlVal (panel, ctl[i], 0);
   
   // update the displayed option number
   SetCtrlVal(panel,PANEL_OPTION, 1);

   break;
 }
 return 0;
}

 

P.S., when you post your project, we don't need your cvibuild directory, the .cdb file, or the .exe file.  They just take up space on NI's server and our drives when we download your posted project.  We just need your .prj file, .uir file, and any .c files and .h files.

0 Kudos
Message 10 of 12
(6,952 Views)