Hello all.
I have a small problem .
How can I, in c#, windows forms aplication,ComboBox, use AutoComplete.
Lets imagine that i have 5 items in the ComboBox that are :
Abcd
Abcdd
Acc
Accd
Add
If i start writing "ab" it will only display items that starts with "ab" .
Or if its impossible, to only be selected the first one, that starts with "ab".
Thanks in advance.

Dani AI

Generated

A short expert add‑on to this thread (references: , , ).

The built‑in ComboBox suggestion behavior that solved the original question is the simplest route when “starts with” matching is acceptable. For more control (match anywhere in the item, case‑insensitive contains, or custom selection behavior) a small custom filter is more flexible. Keep a separate copy of the full item list, filter that list on text changes, and repopulate the ComboBox items while preserving the typed text and caret position.

Example pattern (WinForms):

// keep the original strings
List<string> all = comboBox1.Items.Cast<object>().Select(o => o.ToString()).ToList();

private void comboBox1_TextChanged(object sender, EventArgs e)
{
    string t = comboBox1.Text;
    var matches = all.Where(s => s.IndexOf(t, StringComparison.OrdinalIgnoreCase) >= 0).ToArray();

    comboBox1.BeginUpdate();
    comboBox1.Items.Clear();
    comboBox1.Items.AddRange(matches);
    comboBox1.EndUpdate();

    comboBox1.DroppedDown = matches.Length > 0;
    comboBox1.SelectionStart = t.Length;
    comboBox1.SelectionLength = 0;
}

Notes and troubleshooting

  • If the ComboBox is bound to a DataSource, do not modify Items directly; filter the underlying collection or use a BindingSource and reassign it.
  • For very large lists, debounce the filter (timer) or use a specialized control to avoid UI lag.
  • To simply auto‑select the first matching item (rather than showing suggestions), find the first index with a case‑insensitive Contains/StartsWith and set SelectedIndex.
  • Ensure the control allows typing (DropDown style), and for non‑string objects set DisplayMember or provide a suitable ToString implementation.

This approach preserves the quick built‑in fix noted by while giving practical alternatives for substring matching and data‑bound scenarios.

Recommended Answers

All 6 Replies

No friend it's poosible.
From ComboBox properties let
AutoCompleteMode = SuggestAppend
AutoCompleteSource = ListItems

commented: Thanks for help =) +1
commented: very good solution +4

Ty for the fast answer . Thread solved .
How to flag it as solved ? :F

My pleasure friend, search on Solved in this page I think I can't tell you its location :)

wow, i am impressed, i didnt know it was that easy man!!.
Thanks

My pleasure, Serkan :)

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.