日期:2014-05-16 浏览次数:20974 次
在输入时显示出一个GridControl的方法可行吗,或者还有更好的方法吗
private void txtName_TextChanged(object sender, EventArgs e)
{
DataTable dt = new DataTable();
string sql = "select * from CustInfo where 1=1 ";
if (!string.IsNullOrEmpty(txtName.Text.Trim()))
{
sql += "and CustName like '%" + txtName.Text.Trim() + "%' ";
}
dt = DBHelper.ExecuteDataTableSql(sql);
if (dt.Rows.Count > 0)
{
this.listBoxAuto.Visible = true;
this.listBoxAuto.Items.Clear();
for (int i = 0; i < dt.Rows.Count; i++)
{
if (!listBoxAuto.Items.Contains(dt.Rows[i]["CustName"].ToString()))
this.listBoxAuto.Items.Add(dt.Rows[i]["CustName"].ToString());
}
listBoxAuto.Height = listBoxAuto.ItemHeight * (listBoxAuto.Items.Count + 1);
}
}
private void txtName_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Down)
{