EKsumic's Blog

let today = new Beginning();

Click the left button to use the catalog.

OR

C# ComboBox自动完成功能的示例

首先你得保证

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 18:16:23

* *