winform listbox与textbox组合提示框 模糊查询
private void listbox1_MouseClick(object sender, MouseEventArgs e)
{
textbox1.Visible = false;
textbox1.Text = lsbSearchItem.SelectedItem.ToString();
textbox1.Focus();
textbox1.SelectAll();
}
private void textbox1_KeyUp(object sender, KeyEventArgs e)
{
if (textbox1.Text == "")
{
listbox1.Items.Clear();
listbox1.Visible = false;
return;
}
if (e.KeyCode == Keys.Up)
{
if (listbox1.SelectedIndex > 0)
listbox1.SelectedIndex -= 1;
}
else
if (e.KeyCode == Keys.Down)
{
if (listbox1.SelectedIndex < listbox1.Items.Count - 1)
listbox1.SelectedIndex += 1;
}
else
{
if (e.KeyCode == Keys.Enter)
{
textbox1.Text = listbox1.SelectedItem.ToString();
listbox1.Visible = false;
textbox1.Focus();
textbox1.SelectAll();
}
else
{
listbox1.Items.Clear();
for (int i = 0; i < typeItem.Length; i++)
{
if (str[i].IndexOf(textbox1.Text.Trim()) > 0)
{
listbox1.Items.Add(str[i]);
listbox1.Visible = true;
listbox1.SelectedIndex = 0;
}
}
}
}
上一篇: HTTP请求的缓存(Cache)机制