Re: Radio Button help needed
Quote:
Originally Posted by
clow
This does not seem to work. Am I missing something here?
Thanks!
Yes. The event handlers don't update the member variable. You need to call UpdateData() or do it yourself manually.
Re: Radio Button help needed
So where do I call UpdateData() at exactly? I changed the code to:
Code:
void RadioDialog::OnBnClickedRadioSelection()
{
if(iRadioSelection_== 0)
{
((CButton*)GetDlgItem(IDC_RADIO_ONE))->SetCheck(true);
((CButton*)GetDlgItem(IDC_RADIO_TWO))->SetCheck(false);
((CButton*)GetDlgItem(IDC_RADIO_THREE))->SetCheck(false);
}
else if(iRadioSelection_== 1)
{
((CButton*)GetDlgItem(IDC_RADIO_ONE))->SetCheck(false);
((CButton*)GetDlgItem(IDC_RADIO_TWO))->SetCheck(true);
((CButton*)GetDlgItem(IDC_RADIO_THREE))->SetCheck(false);
}
else if(iRadioSelection_== 2)
{
((CButton*)GetDlgItem(IDC_RADIO_ONE))->SetCheck(false);
((CButton*)GetDlgItem(IDC_RADIO_TWO))->SetCheck(false);
((CButton*)GetDlgItem(IDC_RADIO_THREE))->SetCheck(true);
}
UpdateData();
}
And the button does not change when I click others in the group. Where should I add the UpdateData() call at?
Thanks!
Re: Radio Button help needed
First line in your event handler would work. Keep in mind it will update the values for any other controls you have too.
Another option would be just to check the state yourself
if(GetDlgItem(IDC_RADIO_ONE)->GetCheck())
Re: Radio Button help needed
Putting UpdateData() at the beginning of the handler had mixed results. First when I click IDC_RADIO_TWO then IDC_RADIO_THREE is selected. Also, IDC_RADIO_ONE stays selected also, until I move my mouse over it, then I guess it repaints itself.
Any other ideas what may be wrong?
Re: Radio Button help needed
Yeah. You shouldn't be calling SetCheck yourself. Radio buttons do that for you.
Re: Radio Button help needed
Are your radio buttons BS_RADIOBUTTON or BS_AUTORADIOBUTTON? I would suggest - BS_AUTORADIOBUTTON. Then, as GCDEF stated, you won't need SetCheck() calls.
I also suggest to set the next control (after you radio buttons in the tab order) to Group.