user-interfacemfcccombobox

CComboBox event for making selection by enter key?


I have a dialog with a CComboBox in the DropList style. I want it to call my function (e.g. LoadData()) when:

  1. user clicks an item in the drop list, or
  2. an item in the drop list is highlighted (either by mouse hover or keyboard), and user presses enter

but NOT when the user is still typing text in #2.

Calling LoadData() in the ON_CBN_SELCHANGE handler works fine for #1, but for #2 this event fires on every keystroke instead of only on enter. In other words, if I have combobox items:

1
12
123

and I type 12, it will trigger ON_CBN_SELCHANGE once for 1, once for 12 ... but really I'm trying to type 123, so I don't want those first 2 keystrokes to result in LoadData() calls.

What's the correct way to implement this?


Solution

  • Further to the comments in your question, here is the answer:

    1

    2

        void CMFCApplication1Dlg::OnCbnSelendokCombo1()
        {
            // TODO: Add your control notification handler code here
        }
    

    Now you can proceed as required.


    Alternative

    3

    4