C# ComboBox自动完成功能的示例
Copyright Notice: This article is an original work licensed under the CC 4.0 BY-NC-ND license.
If you wish to repost this article, please include the original source link and this copyright notice.
Source link: https://v2know.com/article/437
首先你得保证
DropDownStyle为DropDown,千万不要是DropDownList,这样会无法输入的。
然后确认接入了数据源,
接入了数据源是指:
using (var Context = new MyDbContext())
{
var GenreData = Context.Genres.OrderByDescending(x=>x.Id);
foreach(var item in GenreData)
{
comboBox1.Items.Add(item.Name);
}
comboBox1.SelectedIndex = 0;
}
最起码这样的。
在窗体初始化的构造方法里面写:
this.comboBox1.AutoCompleteSource = AutoCompleteSource.ListItems; //设置自动完成的源
this.comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend; //设置自动完成的的形式
参考文档:
https://www.cnblogs.com/huangfr/archive/2011/09/07/2170387.html
This article was last edited at 2020-08-22 09:16:23