views:

338

answers:

1

As you may know a CComboBox (DropDownList style) only selects properly by typing if you don't let it autosort it's content. Here an example of what i mean: You type A and then B. If it is not on autosort it will first select the next entry beginning with A and then the next entry beginning with B. If it is sorted it will select the next entry with A and then the next beginning with AB.

I have a class that inherits from CComboBox and it's content is not sorted by the built in sort mechanism. I wanted a proper select-by-typing behaviour, so i implemented that myself. I select the entries by using SetCurSel and then sending a CBN_SELCHANGE message to the parent window.

On Windows XP this worked perfectly fine. We are using Windows 7 now and following problem is occuring now: If i use the mouse to open the dropdown list, select an entry by typing it and then use Tab to jump to the next control, the value that was selected at the beginning is automatically reselected.

If i overwrite OnKillFocus and do the following:

int index = GetCurSel();
CComboBox::OnKillFocus();
SetCurSel(index);

it works generally, but for a moment the old selected value will still flash up which is ugly.

If i don't call CComboBox::OnKillFocus() the correct entry remains selected, but the combo box remains dropped down.

So my next try was to call SetDropDown(FALSE) manually (and nothing else in OnKillFocus()), but then the problem reappears.

So my guess is that if you open the dropdown list the current selection is internally stored. Calling SetCurSel does not update this internal value. And if you tab out that internal value is reselected again.

Any ideas how i can fix this problem?

A: 

Only unverified ideas:

  • Override CB_SHOWDROPDOWN processing. If dropdown list is closed, probably call SetCurSel for a stored item.

  • Override CB_SETCURSEL processing, Add flag indicating whether to process the CB_SETCURSEL message. Turn off the flag on the time of call CComboBox::OnKillFocus() in your code sample.

VitalyVal