ListBox items as AutoCompleteCustomSource for a textbox

后端 未结 3 719
谎友^
谎友^ 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: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)listBox.DataSource);
    

提交回复
热议问题