采用CustomSource当做提示集合
将下列代码添加到窗口加载函数中即可假设unitNameList是获取的想要添加到下拉列表中的字符串列表
AutoCompleteStringCollection collection = new AutoCompleteStringCollection();
// 获取单位列表
List<string> unitNameList = thisgetAllUnitName();
foreach (string unitname in unitNameList)
{
collectionAdd(unitname);
//ConsoleWriteLine("自动提示" + unitname);
}
thiscomboBoxAutoCompleteCustomSource = collection;
thiscomboBoxAutoCompleteSource = AutoCompleteSourceCustomSource;
thiscomboBoxAutoCompleteMode = AutoCompleteModeSuggestAppend;
其中AutoCompleteMode包含NoneSuggestAppend和SuggestAppend四种情况
None关闭自动补全功能
Suggest展开下拉列表并显示匹配的结果
Append自动补全
SuggestAppendSuggest和Append的组合即显示下拉列表也自动补全
直接使用下拉列表中的项作为匹配的集合
AutoCompleteSource设置为ListItems
// 获取单位列表
List<string> unitNameList = thisgetAllUnitName();
foreach (string unitname in unitNameList)
{
thiscomboBoxItemsAdd(unitname);
}
thiscomboBoxAutoCompleteSource = AutoCompleteSourceListItems;