I have a combo box on a binding control. It is bound to a name column in my dataset. It works like it should, but I need the autocomplet to be able to find names by either first name or last name. For example, if I have two names in the name column,
John Smith and
Bob Jones

My user then types in "Jo", I need the dropdown to have both John Smith and Bob Jones listed. Because J and O are the first characters in both a first name and the last name.

Anyone know how I can do this with autocomplete?

Thnks,
Jason

Dani AI

Generated

Short diagnosis: WinForms/TextBox auto-complete matches only from the start of each source string, so a single "John Smith" entry will not be suggested when the user types "Jo" to match "Bob Jones". That explains the behavior reported by @Shataken. @ericstenson's suggestion (filtering at the data source) and @Estella's mention of FindString are both valid directions. Two practical approaches follow—one quick hack, one cleaner UX—with tradeoffs.

Quick, low-effort trick (works well for small/local datasets)

  • For every full-name row, add a second AutoComplete entry that starts with the last name (for example "Jones, Bob"). That makes last names match as if they were at the start of the string while preserving the normal full-name entry so first-name typing still works.
  • Keep entries unique and normalize whitespace/case to avoid duplicates or misleading suggestions.

Cleaner approach (preferred for bound ComboBox or larger datasets)

  • Keep a bound DataTable/BindingSource and implement filtering on text change. When the typed text changes, filter the DataView or run a LINQ query that keeps rows where any name token (first, middle, last) starts with the typed fragment. This displays full names in the dropdown while matching either first or last name.
  • For large datasets, run filtering on a background thread or debounce rapid keystrokes to avoid UI freezes; for server-backed data, perform the search server-side.

Notes and pitfalls

  • Ensure AutoCompleteMode is Suggest or SuggestAppend and AutoCompleteSource is CustomSource when using AutoCompleteStringCollection.
  • For names with multiple parts (hyphenated or compound last names), split intelligently (take the last token as the last name or use a more robust parser).
  • If exact control over display vs. match is needed, prefer the filtering-on-the-binding-source approach so the dropdown always shows the full display name.

Recommended Answers

All 3 Replies

I haven't tried but it is likely tied to your SELECT statement.

try...

WHERE Name LIKE '%" & combobox1 & "%'"

I haven't tried but it is likely tied to your SELECT statement.

try...

WHERE Name LIKE '%" & combobox1 & "%'"

I am not using SQL SELECT. I just created a new collection string from a bound table and assigned it to the autocomplete custom source. I could use code to do it, but wanted to know if there was a way to accomplish it through the autocomplete functionality.
Below is my code:

Dim acFirstName As New AutoCompleteStringCollection
For Each dr As DataRow In Me.WaterworksDataSet.Tables("WorkOrders").Rows
     acFirstName.Add(dr.Item("Name").ToString) 
Next
NameTextBox.AutoCompleteCustomSource = acFirstName

i m not sure if this like what u want
i m using cmbTets.FindString()

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.