Search code examples
winapimfcradio-button

MFC separate groups of radio controls


I have added 8 radio buttons in my dialog layout in the resource manager, but I am having trouble separating them into 2 groups of 4 buttons. I have attempted to add a control variable, but I don't see the option of CButton available in the drop-down menu in the wizard. What would be the easiest method to accomplish this goal?


Solution

    1. Make sure the first control in each group has the "Group" and "Tab Stop" attribute set.
    2. Make sure that the control following the last radio button in each group has the "Group" attribute set.
    3. Make sure that all the radio button IDs in each group are consecutive integers.
    4. Create an integer member variable for each group
    5. In the DoDataExchange method for the dialog add a DDX_Radio statement for each group linking the integer variable to the first ID in the group.

    The integer variables will be set from the radio buttons whenever UpdateData(true) is called (called automatically by the default OnOk() handler) and the radio buttons can be set from the variables by calling UpdateData(false) (happens automatically in the default handling of OnInitDialog)