110,538
社区成员
发帖
与我相关
我的任务
分享
//文本框的文本改变事件
private void txtPN_SMTAI_TextChanged(object sender, EventArgs e)
{
this.lsbPNList_MI.Visible = false;//刚开始listbox不可见
if (txtPN_SMTAI.Text == "")
{
this.lsbPNList_MI.Items.Clear();
this.lsbPNList_MI.Visible = false;//当文本框内容为空时继续不可见
}
else
{
NewMethod();
}
}
//文本框的MouseClick事件
private void txtPN_SMTAI_MouseClick(object sender, MouseEventArgs e)
{
lsbPNList_SMT.Visible = false;
}
private void NewMethod()
{
string sql = "SELECT distinct PN80 from existsModel where PN80 like " + "'%" + this.txtPN_SMTAI.Text + "%'";
DataSet myds = new BLL.ReportManager().GetDateSet_AutoComplete(sql);//这一部分通过SQL语句返回一个DataSet,中间的业务省略了。
if (myds.Tables.Count > 0)
{
if (myds.Tables[0].Rows.Count > 0)
{
this.lsbPNList_SMT.Visible = true;
this.lsbPNList_SMT.Items.Clear();
for (int i = 0; i < myds.Tables[0].Rows.Count; i++)
{
this.lsbPNList_SMT.Items.Add(myds.Tables[0].Rows[i][0]); //将找到的值添加到listBox1索引项中
}
}
else
{
this.lsbPNList_SMT.Visible = false;
}
}
}