0

I use auto completion in a WinForms ComboBox via AutoCompleteMode SuggestAppend and AutoCompleteSource ListItems.

When the box is empty and receives Focus I would like the to show the AutoComplete Dropdown immediately.

Note: I do not mean to open the ComboBox dropdown like

private void comboBox1_Enter(object sender, EventArgs e)
{
    ((ComboBox)sender).DroppedDown = true;
}

(which is a common answer to this question) because the full dropdown is markably different from the more lightweight AutoComplete dropdown, as seen in the comparison:
DropDown Comparison

As far as I found, in Win32 the AutoComplete is set up using SHAutoComplete (link) from shlwapi.dll, however I couldn't find any interaction functions for it.

So, is there a way to open the AutoComplete Dropdown programatically, e.g. via P/Invoke?

Thanks.

Jens
  • 6,275
  • 2
  • 25
  • 51
  • 1
    Does this answer your question? [How to Show AutoComplete Programmatically without entering a text](https://stackoverflow.com/questions/20920492/how-to-show-autocomplete-programmatically-without-entering-a-text) – Sinatr Jun 17 '21 at 09:40
  • Or actually [this one](https://stackoverflow.com/q/54943771/1997232). – Sinatr Jun 17 '21 at 09:41
  • @Sinatr Thank you for the suggestions. I found those earlier but reason I didn't use them are: The second link is actually equivalent to just using `.DroppedDown = true` which is just the normal dropdown, so not what I was looking for. Remaking the whole thing with another listbox is also quite hacky and I don't want to reinvent the wheel. – Jens Jun 17 '21 at 10:02
  • To add: If the answer is: "There is no way to open the normal system dropdown except for entering a character" then that is ok as well. – Jens Jun 17 '21 at 10:05
  • Have you tried to [send keystrokes](https://stackoverflow.com/q/1264227/1997232)? – Sinatr Jun 17 '21 at 10:09
  • None of the above. You can start from here: [How to make autocomplete on a TextBox show suggestions when empty](https://stackoverflow.com/a/53116401/7444103), get a *better view* of what it takes here: [disable key event when the focus is on autocompletion box of textbox](https://stackoverflow.com/a/12760000/7444103), or implement the [IAutoComplete](https://docs.microsoft.com/en-us/windows/win32/api/shldisp/nn-shldisp-iautocomplete) and [IAutoComplete2](https://docs.microsoft.com/en-us/windows/win32/api/shldisp/nn-shldisp-iautocomplete2) Interfaces (and related stuff) *completely* :) – Jimi Jun 17 '21 at 10:14
  • There are other *samples* around. Consider whether you really needs this (not exactly the default behavior - i.e., what Users are accustomed to). I'm not saying that the Autocomplete feature and implementation is *perfect* as it is (also on the devs side), because it's not, by a long shot. – Jimi Jun 17 '21 at 10:18
  • @Jimi Thanks as well! Seems like there really is no direct way to do it. And I agree with you that it is questionable. In the specific use case it would be good to have the menu I guess, but your notion of familiarity is why I didn't want to use any real custom solution. I think I'll leave it as is for now. – Jens Jun 17 '21 at 10:26
  • @Jens "*If the answer is: "There is no way to open the normal system dropdown except for entering a character" then that is ok as well*" - well, `IAutoComplete2` does offer an `ACO_UPDOWNKEYDROPSLIST` option. You could try enabling that option and then simulate a down-arrow key press when needed, for instance. – Remy Lebeau Jun 17 '21 at 14:20

0 Answers0