CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 1999
    Location
    UK (South)
    Posts
    93

    Why wont DDX work for Radio Buttons on a dialog?

    I am creating a dialog it contains some radio buttons and other controls. When I use class wizard to link member variables to the controls nothing comes up for the Radio buttons. How are you supposed to use Radio buttons?

    Simon Pettman


  2. #2
    Join Date
    Jul 2001
    Location
    Austria
    Posts
    62

    Re: Why wont DDX work for Radio Buttons on a dialog?

    Hi,

    I think I know what's your problem. You have to define a group for all the radio buttons that are associated with each other ... I mean, just open the properties of the first radio button and in the "General" tab select "Group". Now you have defined a group.
    Now open the class wizard and you should be able to link a member variable to this radio button.

    Hint: Don't set this option for all the radio buttons !

    Hope it helps :-)
    AcidBurn



  3. #3
    Join Date
    Aug 2000
    Location
    West Virginia
    Posts
    7,721

    Re: Why wont DDX work for Radio Buttons on a dialog?

    There are a number of ways to use radio buttons.
    Here are some notes to give you some ideas:

    1) If you bring up the properties for the radio
    button and check the "group" box, the radio
    button will show up in Class Wizard. However, you
    only want to set this for the first radio button
    in the group.

    2) you can always add the DDX for the button by hand :

    2a) add a member variable :


    CButton m_radioButton1;




    2b) add line in DDX section of CPP file :


    DDX_Control(pDX, IDC_RADIO1, m_radioButton1);




    3) you can access the button as follows :


    CButton *pButton = (CButton *)GetDlgItem(IDC_RADIO1);





    4) you can set a particular button in a group :


    CheckRadioButton( IDC_RADIO1, IDC_RADIO4, IDC_RADIO2 ); // sets the IDC_RADIO2




    5) You can determine which button in the group is checked :


    int IDchecked = GetCheckedRadioButton( IDC_RADIO1, IDC_RADIO4 );





    6) you can associate an "int variable" with the first radio button
    in the group (set its "group" property). In code below, this variable
    is called m_radio ...

    6a) to set a particular button in the group :


    m_radio = 2; // 0 = first button, 1=next button, etc.
    UpdateData(FALSE):




    6b) to see which button is checked :


    UpdateData(TRUE);
    //
    // if m_radio = 0 , first button is checked
    // if m_radio = 1 , second button is checked
    // etc. (I think m_radio = -1 if no button is checked)









Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured