110,535
社区成员
发帖
与我相关
我的任务
分享
AutoCompleteStringCollection acsc =
new AutoCompleteStringCollection();
acsc.AddRange(new string[] {
"1a", "1b", "1c", "1d", "2a", "2b", "3x"
});
this.textBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
this.textBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;
this.textBox1.AutoCompleteCustomSource = acsc;
// 在窗体上加入 BindingSource 控件 bindingSource1
// 在 Form_Load 事件中加入代码
DataTable table = new DataTable();
table.Columns.AddRange(new DataColumn[] {
new DataColumn("ID", typeof(int)),
new DataColumn("Name", typeof(string)),
new DataColumn("Description", typeof(string)) });
for (int i = 0; i < 100; i++)
{
table.Rows.Add(new object[] {
i,
string.Format("Name {0}", i),
string.Format("Description {0}", i) });
}
System.Data.DataView view =
new System.Data.DataView(table);
this.listBox1.DataSource = view;
this.listBox1.DisplayMember = "Name"; // 显示 Name 列的数据
this.bindingSource1.DataSource = view;
// 在 textBox1_TextChanged 事件中加入代码
if (this.textBox1.Text != "")
{
this.bindingSource1.Filter =
string.Format("name like '%{0}%'", this.textBox1.Text);
}