本文介绍了ComboBox.Items.Clear()的替代方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要的是实施以下守则
What I want is to implement the following Code
private void comboBox2_TextChanged(object sender, EventArgs e)
{
SendKeys.Send("{END}");
comboBox2.Items.Clear();
SqlConnection con = new SqlConnection();
con.ConnectionString = Global.constr;
con.Open();
SqlCommand cmd = new SqlCommand("select itemCode from ItemDetails where
ItemCode like '" + comboBox2.Text + "%'
order by ItemCode", con);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
comboBox2.Items.Add(dr[0].ToString());
}
dr.Close();
con.Close();
}
但是当我使用向下箭头选择项目时,代码无效。
comboBox2.Items.Clear();代码也在清除我的文本属性。
搜索没问题。但我无法从列表中选择特定项目。它已被自动清除。
请帮助
提前致谢
But the code is not working when I use the down arrow to choose an Item.
The comboBox2.Items.Clear(); code is clearing my Text Property also.
Searching is fine. But I can't choose the particular item from list. It is been cleared automatically.
Please help
Thanks in advance
推荐答案
private void comboBox2_TextChanged(object sender, EventArgs e)
{
SendKeys.Send("{END}");
//comboBox2.Items.Clear(); NOT HERE
SqlConnection con = new SqlConnection();
con.ConnectionString = Global.constr;
con.Open();
SqlCommand cmd = new SqlCommand("select itemCode from ItemDetails where
ItemCode like '" + comboBox2.Text + "%'
order by ItemCode", con);
SqlDataReader dr = cmd.ExecuteReader();
comboBox2.Items.Clear(); // HERE
while (dr.Read())
{
comboBox2.Items.Add(dr[0].ToString());
}
dr.Close();
con.Close();
}
这篇关于ComboBox.Items.Clear()的替代方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!