Kayot Kayot - 1 year ago 63
Vb.net Question

Combobox Wipes Suggestion When Pressing Enter with Contents Dropped

I'm having this really weird issue with ComboBoxes.

I have a ComboBox populated with entries from a database. However this issue isn't related to the database or it's contents.

When I press the down arrow on the ComboBox, and then type part of an items contents while SuggestAppend is turned on, it wipes the text rather than complete the line. If I just type then the issue doesn't occur. It's only when I drop the list first.

You can recreate this by creating a Combobox on an empty form. Give it a few items, set it's AutoCompleteSource to ListItems and AutoCompleteMode to SuggestAppend.

Now while running the application, drop the list, don't exit this list, just start typing part of an entry. Then press enter. It will wipe the contents of the combo box text.

Is there a way around this bug?

Answer Source

The issue only presents itself when both the suggestion box and the box containing the items are visible at the same time.

Add a KeyPress handler to your combobox and set the DroppedDown property to False like below:

Private Sub YourCombo_KeyPress(sender As Object, e As KeyPressEventArgs) Handles YourCombo.KeyPress
    YourCombo.DroppedDown = False
End Sub

This will close the items box and keep the suggestions box visible. When you press enter it will no longer clear the text.