combobox实现模糊查询

瑟荻
博客专家认证
2015-04-30 07:48:13
combobox自己视线模糊查询,系统自带的只能实现从左到右进行匹配,但是我输入不匹配的就报错:System.ArgumentOutOfRangeException: InvalidArgument=“0”的值对于“index”无效。
       
//绑定原始数据源
private void BindComboBox()
{
string str = "select License from tb_drug";
SQLiteDataReader sdr = sh.getcom(str);
while (sdr.Read())
{
if (sdr[0].ToString() != " " && sdr[0].ToString() != null)
listOnit.Add(sdr[0].ToString());
}
sdr.Close();
this.comboBox1.Items.AddRange(listOnit.ToArray());
}

private void comboBox1_TextUpdate(object sender, EventArgs e)
{
this.comboBox1.Items.Clear();
listNew.Clear();
foreach (string item in listOnit)
{
if (item.Contains(this.comboBox1.Text))
{
listNew.Add(item);
}
}
this.comboBox1.Items.AddRange(listNew.ToArray());
this.comboBox1.SelectionStart = this.comboBox1.Text.Length;
Cursor = Cursors.Default;
this.comboBox1.DroppedDown = true;
}

...全文
190 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
江南小鱼 2015-05-01
  • 打赏
  • 举报
回复
输入不匹配的,哪行代码报错?

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧