ListBox items as AutoCompleteCustomSource for a textbox

后端 未结 3 718
谎友^
谎友^ 2021-01-25 16:48

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

相关标签:
3条回答
  • 2021-01-25 17:34

    Here is a similar question and answer seems to be appropriate. autocomplete textbox on listbox

    Another similar question C# AutoComplete

    0 讨论(0)
  • 2021-01-25 17:37

    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);
    
    0 讨论(0)
  • 2021-01-25 17:51

    The AutoCompleteStringCollection takes only string[], so it should be like this:

    var cc = new AutoCompleteStringCollection();
    cc.AddRange(listBox1.Items.Cast<string>().ToArray());
    
    0 讨论(0)
提交回复
热议问题