0
我能够实现自动完成文本框搜索,但其区分大小写。我想让它变得不敏感。我已经提出或条件,但它只检查输入的第一个字母。我希望搜索完全不区分大小写。Dotnet:如何使自动完成文本框搜索不区分大小写?
下面是我的代码
public partial class Form1 : Form
{
AutoCompleteStringCollection acsc;
public Form1()
{
InitializeComponent();
acsc = new AutoCompleteStringCollection();
textBox1.AutoCompleteCustomSource = acsc;
textBox1.AutoCompleteMode = AutoCompleteMode.None;
textBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;
acsc.Add("Sim Vodafone");
acsc.Add("sim vodafone");
acsc.Add("sIm");
acsc.Add("siM");
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
string d = null;
listBox1.Items.Clear();
if (textBox1.Text.Length == 0)
{
hideResults();
return;
}
foreach (String s in textBox1.AutoCompleteCustomSource)
{
d = textBox1.Text.ToUpper();
if (s.Contains(d) || s.Contains(textBox1.Text))
{
Console.WriteLine("Found text in: " + s);
listBox1.Items.Add(s);
listBox1.Visible = true;
}
}
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
textBox1.Text = listBox1.Items[listBox1.SelectedIndex].ToString();
hideResults();
}
void listBox1_LostFocus(object sender, System.EventArgs e)
{
hideResults();
}
void hideResults()
{
listBox1.Visible = false;
}
}
}
感谢您的回答。它非常简单。我创建了一个ListBox – Prachur 2011-03-17 07:43:22