我正在为杂货店或商店制作一个c# 项目。在那里我有一个数据网格,我在其中对单元格进行了编程以自动建议并且它工作正常。
只有一个问题。我希望数据网格中的一列(例如条形码列)成为仅具有自动建议功能的文本框,而不是所有列。
private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
var source = new AutoCompleteStringCollection();
string cnn = (@"Data Source=TaLy-PC;Initial Catalog=dbMarketi;Integrated Security=True;Pooling=False");
SqlConnection connection = new SqlConnection(cnn.ToString());
SqlCommand command = new SqlCommand("Select Barcode FROM tblDepo", connection);
try
{
connection.Open();
{
SqlDataReader drd = command.ExecuteReader();
while (drd.Read())
{
// this.comboBoxEx1.Items.Add(drd.GetString(0).ToString());
source.AddRange(new string[] { drd.GetString(0).ToString() });
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
connection.Close();
TextBox dgvEditBox = e.Control as TextBox;
if (dgvEditBox != null)
{
dgvEditBox.AutoCompleteMode = AutoCompleteMode.Suggest;
dgvEditBox.AutoCompleteCustomSource = source;
dgvEditBox.AutoCompleteSource = AutoCompleteSource.CustomSource;
}
}