Access the answers to your technology questions today.
Subscribe Now
30-day free trial. Register in 60 seconds.
What Makes Experts Exchange Unique?
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.
Try it out and discover for yourself.
Subscribe Now
30-day free trial. Register in 60 seconds.
Join the Community
Give a Little. Get a Lot.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Join the Community
by: DanRollinsPosted on 2009-04-25 at 17:35:26ID: 24234080
Here is the MFC way to handle a group of radio buttons automatically -- you should never have to do SetCheck()
will add a DDX_Radio(...) to the DoDataExchange for the dlg.
In the dialog editor, make sure the tab-order of the radio buttons are sequential.
Then in only the first radio button, set the Group checkbox in its properties.
Then right-click that first button and press Ctrl+W (class wizard)
In the Variables page, only the first radio button is listed. Give it a variable name, say,
m_nRadioGrpSel
This
Now before you open the dialog, set the member variable to indicate which radio button is set (0...n-1). For instance:
CMyDialog dlg;
dlg.m_nRadioGrpSel= 0; // pre-select the first Rb
if ( IDOK == dlg.DoModal() ) {
if ( dlg.m_nRadioGrpSel==2 ) {
// the third Rb was selected
}
}
If you set...
dlg.m_nRadioGrpSel= -1; // or other invalid value
then none of the radio buttons will be selected when the user first sees the dialog box. Furthermore, the user will not be able to use the Tab key to get to any of the radio buttons in the group (so he can't accidentally select one except by using the mouse).
So we have a way to determine not just the status of individual buttons but the group as a whole, and we can set the desired option on screen by just putting a number (0,1,2...) into a member variable and then using
UpdateData(FALSE)
And conversely, we can set the variable to match the current selection by using:
UpdateData( TRUE )
I think the comments in the attached code should cover it.
Select allOpen in new window