Combobox and autocomplete in C #

I have a little problem with the autocomplete parameter in combobox. Everything works correctly, except that I want to work with it :)

When I start typing in combobox, autusuggest works the way I like:

Combo

But when I open combobox first and then start typing, I get something like this:

enter image description here

The more I can not select an item from the list of auto messages, only from this list.

AutocompleteMode is SuggestAppend

I would like to have autosuggest, as in the first picture, and in situations like Figure 2, this first list of lists with a list should be closed somehow ..

+6
source share
7 answers

I had the same problem and solved it like this:

private void comboBox_DropDown(object sender, EventArgs e) { ComboBox cbo = (ComboBox)sender; cbo.PreviewKeyDown += new PreviewKeyDownEventHandler(comboBox_PreviewKeyDown); } private void comboBox_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) { ComboBox cbo = (ComboBox)sender; cbo.PreviewKeyDown -= comboBox_PreviewKeyDown; if (cbo.DroppedDown) cbo.Focus(); } 

As soon as the user clicks on the DropDown PreviewKeyDown button, a ComboBox joins it. When the user starts typing, the newly added event is fired. In this case, we check if there is a ComboBox DroppedDown , if so, the focus is the ComboBox . On ComboBox DropDown focus disappears and that it is.

+12
source

How about using DropDown and DropDownClosed events to disable or change autocomplete mode?

+5
source

I had the same problem. I tried the DropDown and DropDownClosed events to set the AutoCompleteMode property to equal and suggest. In this situation, the SelectedIndexChanged event does not fire after the selection of an item with the mouse. I used the SelectedValue property in the SelectedIndexChanged event, and this property is already changed at the time the DropDownClosed event is fired. In my case, I just called the SelectedIndexChanged method from the DropDownClosed event to solve the problem.

+3
source

Implement an event in ComboBox KeyDown. It should look like this.

 void cmbExample_KeyDown(object sender, KeyEventArgs e) { if ((sender as ComboBox).DroppedDown) (sender as ComboBox).DroppedDown = false; } 
+3
source

Have you tried other possible values ​​for AutoCompleteMode which are Append , None and Suggest ? I think you are looking for Suggest instead of AppendSuggest .

Here's some downloadable sample code illustrating the different modes if you need it.

+2
source

I also found that the default UI implementation is distracting because the two drop-down lists fight for mouse control.

You want to hide the drop-down list when displaying auto-fill suggestions. Before submitting auto-complete offers, a message appears with windows. I decided to roll the throttle in response to this message. This requires a slight override of the drop-down list:

 Public Class Combobox2 Inherits ComboBox Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message) If m.Msg = 135 AndAlso DroppedDown Then 'WM_GETDLGCODE DroppedDown = False End If MyBase.WndProc(m) End Sub End Class 
+2
source
 void cmbExample_KeyDown(object sender, KeyEventArgs e) { cmbExample.DroppedDown = false; } 
0
source

Source: https://habr.com/ru/post/889817/


All Articles