我有两gridview
textbox
列。我在gridview
'textbox
列中单独使用自动完成,但两gridview
textbox
列的自动完成都在这些列中混合数据。
如何在不混合来自article_code
和的数据的情况下显示自动完成yarn_count
?
这是我的代码:
AutoCompleteStringCollection namesCollection4=new AutoCompleteStringCollection();
string query = "select article_code from article_production";
con.Open();
SqlCommand cmb = new SqlCommand(query, con);
SqlDataReader dr = cmb.ExecuteReader();
if (dr.HasRows == true)
{
while (dr.Read())
{
namesCollection4.Add(dr["article_code"].ToString());
}
}
else
{
MessageBox.Show("Data not found");
}
con.Close();
dr.Close();
int column = dataGridView1.CurrentCell.ColumnIndex;
if(column==8)
{
TextBox tb = e.Control as TextBox;
if (tb != null)
{
tb.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
tb.AutoCompleteCustomSource = namesCollection4;
tb.AutoCompleteSource = AutoCompleteSource.CustomSource;
}
}
第二个 Gridview 列
AutoCompleteStringCollection namesCollection1=new AutoCompleteStringCollection();
string query1 = "select yarn_count from yarn";
con.Open();
SqlCommand cmb1 = new SqlCommand(query1, con);
SqlDataReader dr1 = cmb1.ExecuteReader();
if (dr1.HasRows == true)
{
while (dr1.Read())
{
namesCollection1.Add(dr1["yarn_count"].ToString());
}
}
else
{
MessageBox.Show("Data not found");
}
con.Close();
dr1.Close();
int column1 = dataGridView1.CurrentCell.ColumnIndex;
if (column1 == 9)
{
TextBox tb1 = e.Control as TextBox;
if (tb1 != null)
{
tb1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
tb1.AutoCompleteCustomSource = namesCollection1;
tb1.AutoCompleteSource = AutoCompleteSource.CustomSource;
}
}