in my program i have a dialog that contains a group of radio buttons.
everytime you make a radio button selection, a messagebox appears asking the user whether or not they want to confirm this selection.
the problem i am experiencing is when the user tries to cancel the selection.
for example, in a handler for one the of the radio buttons:
Code:
void radioBtnDlg::OnBnClickedRadio1()
{
// TODO: Add your control notification handler code here
if(MessageBox(MSG_0, MSG_1, MB_OKCANCEL) == IDOK)
{
// get data from dialog selection.
UpdateData(TRUE);
}
else
{
// need to return dialog to previous state.
UpdateData(FALSE);
}
}
after selecting cancel, if you then click the main window to unset the focus from the dialog, then set focus back to the dialog, this handler is called again! So then the messagebox keeps re-appearing.
Anyone know why this is occurring? Am i doing something wrong?
it is a very simple app that just points out the problem i am experiencing.
make a radio button selection, then when a messagebox appears, click cancel to cancel the selection. then click on the main window to set focus to the main window, then click on the dialog window to set focus back to the dialog window. the messagebox re-appears because the handler for the radio button was called again!
Don't make it that complex. UpdateData should not bet called until and unless user has pressed Apply or OK button. Your program should store the last "selection" (as a variable within the class).
For instance you have 3 radio buttons, and you want to confirm only for third button selection (let assume that selection is critical). So when The message handler is called for that selection, you should do something like:
Code:
if ( confirm_from_user != IDOK)
{
// Restore last selection by calling CheckRadioButton
}
ajay, i tried your method to avoid the call to updatedata(false) if user cancels, and instead manually set radio button states to what they were with checkradiobutton. however, the problem is still there.
i think my call to updatedata(false) is no different then manually setting radio buttons. i have a member variable in dodataexchange tied to this groups of buttons. if user cancels selection, that member variable already contains the previous selected state, so by calling updatedata(false), i would think that should simply update the radio buttons to the value of the member variable (which already has previous state).
in the 2nd post of this thread, i uploaded the sample app. kudos to someone who can find a solution. i found a solution but it is a little bit wierd and trying to find a better solution.
I've not looked at your project, neither I think I should need it.
The basic problem is: bad User Interface design.
You are calling UpdateData(FALSE), just to restore the previous value. What about the other controls your dialog may have (I assume).
For example there is a text box which is empty by default, combo box that shows 10 items. Now if user enters "Codeguru.com" in editbox, and also selects 4th item from combobox. Further to this, he/she selects this radio button.
Jeez! All the controls are now restored to default values (empty text box and 1st item selected in combo) - just because user has "tried" to select a radio box option???
One more important thing: I am not saying about the regular variable for radio button, that is referenced in DoDataExchange - it is related to UpdateData. Do have a variable that keeps track of current user selection (just like Edit box contents are stored somewhere).
ajay, you have a good point about the updatedata. but if i understood your solution you suggested earlier, it is to not use updatedata and instead manually set the radio button state directly. well, i tried that and it didn't solve the problem either. but anyways, thanks for your input.
Last edited by kashikoi; June 8th, 2006 at 02:50 PM.
if(MessageBox(MSG_0, MSG_1, MB_OKCANCEL) == IDOK)
{
// get data from dialog selection.
UpdateData(TRUE);
}
else
{
// need to return dialog to previous state.
UpdateData(FALSE);
}
See, in this case UpdateData is changing the "state" of radio button. Due to the change, handler is called. It does not matter how 'state' is changed: by end user, DoDataExchange, CheckRadioButton, SendMessage....
Please read my previous post, and try to grasp it!
ajay, so regardless what method i use to change state of the radio button (updata(false), checkradiobutton, etc...), handler for radio button is called?
the problem i am seeing here is this:
user selects radio button..
radio button state has now changed..
this will cause handler for the radio button to be called..
message box is displayed..
user selects cancel..
now here is the problem. since the user already made that first selection (which is why we are here at this point in the program), how is it possible to change the radio button state back to what it was before the user made that initial selection, without causing handler to be called again..
since the initial implication is that handler is called whenever radio button state changes, then this appears to be impossible.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.