locked
Radio button starting position RRS feed

  • Question

  • Hi All,

    I’m working with Visual Studio 2010 C++.

    On my program when I’m opening the Dialog there are two radio buttons that I want one of them to selected.

    How should I make one of them to be selected when I open the dialog?

    Thanks,

    Shimon.

    Monday, July 15, 2013 10:18 AM

Answers

  • You must send the BM_SETCHECK message to the radio button control you want to change. Using GetDlgItem and the correct Item ID you will find out the window handle that belongs to the specific radio button.

    Best regards

    Bordon

    Note: Posted code pieces may not have a good programming style and may not perfect. It is also possible that they do not work in all situations. Code pieces are only indended to explain something particualar.

    • Marked as answer by ShimonShami Tuesday, July 16, 2013 1:45 PM
    Monday, July 15, 2013 10:26 AM
  • I was thinking you are doing plain API since you did not mentioned something about MFC!

    MFC makes everything easier using DDX/DDV:-) You only need to add an variable that is associated to your first radio button control. In your dialog class you open the context menu in class view, and select "Add - Add variable". Select Checkbox "Control Variable". Than you see your control IDs. Select the control Id of your first radio button in your radio button group. Set as variable type int, and give it a variable name.

    That was it. Depending on how you will set the radio button you need to call CWnd::UpdateData.


    Best regards

    Bordon

    Note: Posted code pieces may not have a good programming style and may not perfect. It is also possible that they do not work in all situations. Code pieces are only indended to explain something particualar.


    • Edited by Bordon Monday, July 15, 2013 12:57 PM ----
    • Marked as answer by ShimonShami Tuesday, July 16, 2013 1:45 PM
    Monday, July 15, 2013 12:57 PM
  • Call the dialog's CheckRadioButton function in OnInitDialog.
    • Marked as answer by ShimonShami Tuesday, July 16, 2013 1:45 PM
    Monday, July 15, 2013 1:03 PM
  • Ok. 2 ways

    the first one : click the No radio button and change its properties ,set group" false ",meanwhile,

                           change the Yes button properties, set group "true".

    the second one: add variable to Yes button, use the function .setcheck(1) .

             

    • Proposed as answer by ooo_O Tuesday, July 16, 2013 1:16 AM
    • Marked as answer by ShimonShami Tuesday, July 16, 2013 1:45 PM
    Monday, July 15, 2013 5:17 PM
  • Hi Bordon,

    • The Program is MFC C++ on the Visual Studio 2010.
    • I really don’t understand how to do it…
    • Let me explain my problem I’ve got on the Dialog named IDD_Diag two Radio buttons that grouped together.
    • The first is No and the second Yes.
    • Now when I open the IDD_Diag no one is selected.
    • I need that on default when I open the IDD_Diag the Yes will be selected.
    • How can I do it?
    • I presume that I need to put a command on the contractor that do it.

    Thanks,

    Shimon.


    Just read below articles

    Radio Buttons in MFC (Visual Studio 2008 / C++)

    Using Radio Buttons


    Thanks, Renjith V R

    • Marked as answer by ShimonShami Tuesday, July 16, 2013 1:45 PM
    Tuesday, July 16, 2013 6:12 AM

All replies

  • You must send the BM_SETCHECK message to the radio button control you want to change. Using GetDlgItem and the correct Item ID you will find out the window handle that belongs to the specific radio button.

    Best regards

    Bordon

    Note: Posted code pieces may not have a good programming style and may not perfect. It is also possible that they do not work in all situations. Code pieces are only indended to explain something particualar.

    • Marked as answer by ShimonShami Tuesday, July 16, 2013 1:45 PM
    Monday, July 15, 2013 10:26 AM
  • Hi Bordon,

    • The Program is MFC C++ on the Visual Studio 2010.
    • I really don’t understand how to do it…
    • Let me explain my problem I’ve got on the Dialog named IDD_Diag two Radio buttons that grouped together.
    • The first is No and the second Yes.
    • Now when I open the IDD_Diag no one is selected.
    • I need that on default when I open the IDD_Diag the Yes will be selected.
    • How can I do it?
    • I presume that I need to put a command on the contractor that do it.

    Thanks,

    Shimon.


    • Edited by ShimonShami Monday, July 15, 2013 11:30 AM Editing...
    Monday, July 15, 2013 11:22 AM
  • I was thinking you are doing plain API since you did not mentioned something about MFC!

    MFC makes everything easier using DDX/DDV:-) You only need to add an variable that is associated to your first radio button control. In your dialog class you open the context menu in class view, and select "Add - Add variable". Select Checkbox "Control Variable". Than you see your control IDs. Select the control Id of your first radio button in your radio button group. Set as variable type int, and give it a variable name.

    That was it. Depending on how you will set the radio button you need to call CWnd::UpdateData.


    Best regards

    Bordon

    Note: Posted code pieces may not have a good programming style and may not perfect. It is also possible that they do not work in all situations. Code pieces are only indended to explain something particualar.


    • Edited by Bordon Monday, July 15, 2013 12:57 PM ----
    • Marked as answer by ShimonShami Tuesday, July 16, 2013 1:45 PM
    Monday, July 15, 2013 12:57 PM
  • Call the dialog's CheckRadioButton function in OnInitDialog.
    • Marked as answer by ShimonShami Tuesday, July 16, 2013 1:45 PM
    Monday, July 15, 2013 1:03 PM
  • Ok. 2 ways

    the first one : click the No radio button and change its properties ,set group" false ",meanwhile,

                           change the Yes button properties, set group "true".

    the second one: add variable to Yes button, use the function .setcheck(1) .

             

    • Proposed as answer by ooo_O Tuesday, July 16, 2013 1:16 AM
    • Marked as answer by ShimonShami Tuesday, July 16, 2013 1:45 PM
    Monday, July 15, 2013 5:17 PM
  • Hi Bordon,

    • The Program is MFC C++ on the Visual Studio 2010.
    • I really don’t understand how to do it…
    • Let me explain my problem I’ve got on the Dialog named IDD_Diag two Radio buttons that grouped together.
    • The first is No and the second Yes.
    • Now when I open the IDD_Diag no one is selected.
    • I need that on default when I open the IDD_Diag the Yes will be selected.
    • How can I do it?
    • I presume that I need to put a command on the contractor that do it.

    Thanks,

    Shimon.


    Just read below articles

    Radio Buttons in MFC (Visual Studio 2008 / C++)

    Using Radio Buttons


    Thanks, Renjith V R

    • Marked as answer by ShimonShami Tuesday, July 16, 2013 1:45 PM
    Tuesday, July 16, 2013 6:12 AM
  • Thanks a lot,

    Shimon.

    :) :=)

    Tuesday, July 16, 2013 1:44 PM