DataGridView单元格自动完成

注意:该方法最大的不足之处就是会导致表格很卡,忘高手知道怎么规避卡的现象就指点一二(已修正)

private void GridDetail_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
if (GridDetail.CurrentCell.ColumnIndex != 1)
return;
TextBox tb = e.Control as TextBox;
tb.AutoCompleteSource = AutoCompleteSource.CustomSource;
tb.AutoCompleteMode = AutoCompleteMode.Suggest;
//定义一个数组
string[] array = new string[] { "11", "12", "13", "22", "23", "24" };
//整体赋值给AutoCompleteCustomSource
tb.AutoCompleteCustomSource.AddRange(array);
//List<string> list = new List<string>();
//list.AddRange(new string[] { "11", "12", "13", "22", "23", "24" });
//循环赋值会导致卡的现象
//foreach (string s in list)
//tb.AutoCompleteCustomSource.Add(s);
}




posted @ 2012-03-23 18:10  ghypnus  阅读(420)  评论(0编辑  收藏  举报