Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Force user choice in combobox

Status
Not open for further replies.

WebdudeIA

Programmer
Jul 26, 2002
11
0
0
US
How do I force a user to make a choice on a combobox? I don't want the user to move off the combo box until a choice has been made.

 
I'm not sure I follow correctly but can't you just ensure that there's always a selection in the combo box? In other words, when the combo is first displayed (perhaps in the dialogs 'OnInitDialog()' function) use the combo's 'SetCurSel()' function to ensure a selection is already made. That way, there is no way the user can 'OK' the dialog without a selection being made from the combo.
 
Actually I need to start with a reason not chosen. There really isn't any appropriate default selection.

I can disable other dialog objects (buttons, grid, etc.) and wait for the user to select a reason before reactivating the other items. I can also trap for the user attempting to focus on other elements of the dialog.

I was just hoping that there were a simpler method to focus on the combobox and force the user to stay there until a selection was made.

Thanks.
 
you can set the focus on that combobox and if the user attempts to lose focus on that combobox you can have some trap to check if the combobox has data.
 
And how would I check for the combobox to "lose" focus?
 
I don't rmeember if there was a way to set something to reply on un focus (but I'm sure there is)... But anyways - a decent work around would be to check when on focus of other controls, it will check and reset control to the combobox should it not be filled out.
 
There is CWnd function called OnKillFocus. But your dialog would have to be derived from CWnd.
Check the syntax in the MSDN Library.
hope it helps.



 
The simplest explanation is usually the best. If I was faced with this problem, I would check to see whether the user had made a valid selection in the combo before dismissing the dialog when the user clicks 'OK'. If not, don't dismiss it and display some kind of error message box instead saying they need to make a valid selection from the combo before continuing.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top