如何将TextBox的AutoCompleteSource链接到实体框架

时间:2015-11-09 15:32:06

标签: c# entity-framework linq autocomplete textbox

我有一个表“Clients”和一个名为tbClient的文本框,但我不知道如何使用实体框架和文本框上的LINQ实现自动完成。这就是我实际上

 var client = from a in ca.Clients select new { a.Name, a.DNI, a.Address, a.Phone, a.Email};
 var cli = client.ToList();
 dgvClient.DataSource = cli;

填写datagridview

1 个答案:

答案 0 :(得分:2)

我解决了

var name = from a in ca.Clients select a.Name;
AutoCompleteStringCollection sourcename = new AutoCompleteStringCollection();
sourcename.AddRange(name.ToArray());
this.tbName.AutoCompleteMode = AutoCompleteMode.Suggest;
this.tbName.AutoCompleteSource = AutoCompleteSource.CustomSource;
this.tbName.AutoCompleteCustomSource = sourcename;