111,131
社区成员
发帖
与我相关
我的任务
分享
List<string> list = new List<string>();
List<string> listNew = new List<string>();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
comboBox1.DataSource = null;
list.Add("a");
list.Add("aa");
list.Add("abc");
list.Add("bcc");
comboBox1.DataSource = list;
comboBox1.SelectedIndex = -1;
}
private void comboBox1_TextChanged(object sender, EventArgs e)
{
string text = comboBox1.Text;
if (text == "")
{
return;
}
else
{
listNew = list.FindAll(s => s.Contains(text));
comboBox1.DataSource = listNew;
comboBox1.DroppedDown = true;
if (listNew.Count > 0)
{
//comboBox1.SelectedIndex = 0;
comboBox1.SelectionStart = text.Length;
}
}
}