I have populated some items into a listbox using the datasource property. Now I need to set the AutoCompleteCustomSource for a textBox from the items listed in the listbox. Prec
Here is a similar question and answer seems to be appropriate. autocomplete textbox on listbox
Another similar question C# AutoComplete
If your ListBox is a list of strings, you should be able to do this: (untested)
textBox.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
textBox.AutoCompleteSource = AutoCompleteSource.CustomSource;
textBox.AutoCompleteCustomSource.AddRange((List<String>)listBox.DataSource);
The AutoCompleteStringCollection
takes only string[]
, so it should be like this:
var cc = new AutoCompleteStringCollection();
cc.AddRange(listBox1.Items.Cast<string>().ToArray());