Share via

ComboBox autocomplete does not trigger SelectedIndexChanged

James Buss 136 Reputation points
2023-07-18T03:47:32.4233333+00:00

I have a form. When it opens, it loads a selected record from the database and the user can edit the record and save the changes. On the form are a couple of ComboBoxes. The list source for the comboboxes are from data tables within the database. I've set DropDownStyle = DropDown, AutoCompleteMode = Append, AutoCompleteSource = ListItems. I have some code that needs to execute when the SelectedIndex field changes, so I've used the SelectedIndexChanged event.

When the program runs, the first time the form is opened to edit a record, if the user knows which item they want to select without actually using the list, the user can start to type it in the ComboBox (instead of clicking the drop down arrow and selecting in the list), and AutoComplete will fill in the rest of whatever matches. When the user presses Tab to accept the appended field value and move to the next field, the SelectedIndexChaged event is triggered and the code runs.

However, subsequent times where the form is opened to edit a different record, if the user begins typing in the ComboBox and there is an item in the list that matches, AutoComplete will append the rest. However, on all the subsequent times the form is used, pressing Tab to move to the next record will not trigger the SelectedIndexChanged event.

The way it works the first time using the form, is the desired result. The subsequent times are not. I'm at a loss as to why this is happening. I'm using VS 2019 and coding in VB. I did something similar a number of years ago using VS 2010 and it worked perfectly every time. I've checked the ComboBox properties and the code and the only thing that I can see that is different is that in the VS 2010 program, when the form opened, it called AddNew() to add a new record to the database, which the user then filled out the appropriate values, but in this new program in VS 2019, the form opens and calls TableAdapter.FillByID(dataset, RecordID) and the user edits an existing record.

Any ideas what is going on or what I can do about it? I prefer the AutoComplete.Append instead of using DropDownList because DropDownList only matches on the first letter of each item in the list. When you have multiple entries with the same first letter (e.g. James, Jane, Joanne, John, Jon), it's nice if the user can type more than the first letter to get the item in the list.

Developer technologies | Windows Forms
Developer technologies | .NET | Other
Developer technologies | VB
Developer technologies | Visual Studio | Other
Developer technologies | Visual Studio | Other

A family of Microsoft suites of integrated development tools for building applications for Windows, the web, mobile devices and many other platforms. Miscellaneous topics that do not fit into specific categories.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.