dategridview控件怎么实现自动完成功能?先看下效果图:
private AutoCompleteStringCollection autoCompleteSource = new AutoCompleteStringCollection();
2
3 private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
4 {
5 DataGridView dgv = (DataGridView)sender;
6 if (e.Control is TextBox)
7 {
8 TextBox tb = (TextBox)e.Control;
9 if (dgv.CurrentCell.OwningColumn.Name=="Name")
10 {
11 tb.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
12 tb.AutoCompleteSource = AutoCompleteSource.CustomSource;
13 tb.AutoCompleteCustomSource = this.autoCompleteSource;
14 }
15 else
16 {
17 tb.AutoCompleteMode = AutoCompleteMode.None;
18 }
19 }
20 }
21
private AutoCompleteStringCollection autoCompleteSource = new AutoCompleteStringCollection();
2
3 private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
4 {
5 DataGridView dgv = (DataGridView)sender;
6 if (e.Control is TextBox)
7 {
8 TextBox tb = (TextBox)e.Control;
9 if (dgv.CurrentCell.OwningColumn.Name=="Name")
10 {
11 tb.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
12 tb.AutoCompleteSource = AutoCompleteSource.CustomSource;
13 tb.AutoCompleteCustomSource = this.autoCompleteSource;
14 }
15 else
16 {
17 tb.AutoCompleteMode = AutoCompleteMode.None;
18 }
19 }
20 }
21