In a dialog (CDialog), I want to initially disable the OK button until the
user selects an item in a list box on that dialog. When an item is selected I
want to enable the OK button and give it focus (so that the button has a bold
outline showing that it has focus).
What I get is: The OK button is initially disabled (greyed out). There is no
initial selection in the list box. When a selection is made in the list box,
the OK button is enabled but it does not visually seem to have focus. When a
*second* selection is made in the list box, the OK button is given focus.
I do the following:
dialog data (set up using "Add Variable"):
CListBox cListBox;
CButton cOK;
in OnInitDialog():
cOK.EnableWindow(FALSE):
in OnLbnSelchangecListBox() -- when the list box selection changes:
cOK.EnableWindow(TRUE);
cOK.SetFocus();
What am I doing wrong?
Thanks
I don't know, but FYI if the OK button is the default button, you don't need
to set the focus to it in order for it to click when you press the Enter
key.
-- David
Since there is no need to change the focus to the OK button, there is no need to do this
at all.
joe
Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
In a dialog you should use
GotoDlgCtrl(&cOk);
instead.
See MSDN for
void CDialog::GotoDlgCtrl(CWnd*);
Thanks. I checked and the OK button is indeed the default button.
I would like the OK button to have the outside border that indicates the
control has focus. Most dialogs work this way by default, but I started out
disabling the control in OnInitDialog() and now I can't get the border to
return on the first call to SetFocus(). On the second and subsequent calls
the border appears.
Tom
I see your point. If the user wanted to chage the selection, they would have
to click the list box once just to give it focus.
Tnx, Tom
Tom,
Don't use SetFocus, use WM_NEXTDLGCTL instead.
Dave