0

The standard Windows/MFC ComboBox (dropdown-mode) has an auto-complete feature that I'd like to turn off, but don't know how.

Example 1: Create a ComboBox with the list values "Abc" and "Def". Enter "A" as edit value and use the drop-down-button. "A" will be changed to "Abc".

Example 2: Same start values. Open the drop down, enter "A" as edit value and press TAB. "A" will be changed to "Abc".

These examples even work in the Visual Studio IDE dialog editor test mode. No compiled exe needed.

The change from "A" to "Abc" is probably a feature, but it's not wanted by the customer. Is there any way to prevent it?

user178379
  • 240
  • 2
  • 11

1 Answers1

0

You can finetune autocomplete behavior of any Edit control by calling SHAutoComplete. To get a handle to the Edit control part of a ComboBox send a CBEM_GETEDITCONTROL message to the ComboBox control.

To remove the unwanted feature the flags for SHAutoComplete must not include SHACF_USETAB.

IInspectable
  • 46,945
  • 8
  • 85
  • 181
  • Thanks, sounds good, but doesn't seem to work. I just tested it with SHACF_AUTOAPPEND_FORCE_OFF|SHACF_AUTOSUGGEST_FORCE_OFF for the dialog, the combo box and the combo boxes edit control. All return S_OK, but the problem stays. – user178379 Aug 20 '13 at 11:09
  • For both flags the documentation requires the following: *"This flag must be used in combination with one or more of the SHACF_FILESYS** *or SHACF_URL** *flags."* – IInspectable Aug 20 '13 at 11:53
  • Oops, you're right of course. Tried it with SHACF_AUTOAPPEND_FORCE_OFF|SHACF_AUTOSUGGEST_FORCE_OFF|SHACF_FILESYSTEM|SHACF_URLALL. Again all return S_OK, but the problem remains. – user178379 Aug 20 '13 at 12:31
  • Used only SHACF_DEFAULT just for the heck of it and that had an interesting effect: I was able to auto-complete URLs and paths with my combo-box. So my call is applied to the right HWND. I think this function was made only to configure the URL/path auto-complete and not for the auto-complete with the dropdown data... – user178379 Aug 20 '13 at 12:33
  • @user It seems you are right, the `SHAutoComplete` is indeed just for files/folders/shell namespaces. To disable autocomplete it seems you would have to create an `IAutoComplete` COM object and implement a trivial `IEnumString` source, that doesn't return anything. You might also have to adjust the behavior by calling `IAutoComplete2::SetOptions`. With ATL being notoriously under-documented and over-featured I wouldn't be surprised if it already has all the ingredients, ready to be pieced together. – IInspectable Aug 20 '13 at 21:01
  • Sigh, couldn't get that to work either. But it might be my fault, these COM things are quite complex. I used http://www.codeproject.com/Articles/2371/IAutoComplete-and-custom-IEnumString-implementatio to implement it but effectively couldn't disable the auto-complete in any way. I'm not sure if this is the right way either. Documentation for IAutoComplete refers to edit controls and comboboxex. But doesn't mention regular combobox'es. – user178379 Aug 21 '13 at 09:17