我正在尝试创建一列,该列将在我开始输入该行时提出建议,而数据建议将出现在SQL表中,我尝试在此处和其他站点中使用一些代码,但似乎对我而言均无法正常工作需求。
这是我尝试过的代码之一:
DataGridViewTextBoxColumn txt = new DataGridViewTextBoxColumn();
txt.Name = "Product Code";
txt.Width = 250;
dataGridView1.Columns.Add(txt);
con.Open();
try
{
cd = new SqlCommand();
cd.Connection = con;
cd.CommandText = "SELECT * FROM tblmaster";
da = new SqlDataAdapter();
da.SelectCommand = cd;
dt = new DataTable();
in the data source.
da.Fill(dt);
foreach (DataRow r in dt.Rows)
{
if (e.Control is TextBox)
{
DataGridViewTextBoxEditingControl txt = e.Control as DataGridViewTextBoxEditingControl;
txt.AutoCompleteCustomSource.Add(r.Field<string>("Product Code"));
txt.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
txt.AutoCompleteSource = AutoCompleteSource.CustomSource;
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
da.Dispose();
con.Close();