winform中Combobox模糊下拉

jnshijin 2009-11-26 09:01:56
这个Combobox已经绑定了数据库的资料:
例如有:
A1
A2
B1
B2
C1
C2
当我输入C的时候Combobox下拉列表绑定C1,C2,就是用输入的关键字模糊下拉出相应的内容,类似于Google搜索的下拉效果 。
多谢各位!
...全文
724 25 打赏 收藏 转发到动态 举报
写回复
用AI写文章
25 条回复
切换为时间正序
请发表友善的回复…
发表回复
MagicStone2008 2009-12-17
  • 打赏
  • 举报
回复
this.comboBox1.DisplayMember = "Kind";
this.comboBox1.ValueMember = "id";
this.comboBox1.Text = string.Empty;
this.comboBox1.DataSource = bind;
daichenghua 2009-11-27
  • 打赏
  • 举报
回复
comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
comboBox1.AutoCompleteSource = AutoCompleteSource.ListItems
ireenter 2009-11-27
  • 打赏
  • 举报
回复
我已经重新封装了,你下载就可以使用了,支持汉字的声母查询,结局了在tablelayout内部的问题。
http://download.csdn.net/source/1795800
l171147904 2009-11-27
  • 打赏
  • 举报
回复
被楼主头像吸引了。。。

1,2楼可解决问题

若如 16楼所说,给 控件添加 onKeyPress 事件可解决!

每次输入字符都 触发,去处理
zhengkai85 2009-11-27
  • 打赏
  • 举报
回复
我按我理解的楼主的意思 应该这样解
Combobox输入内容时 重新绑定数据源 带上模糊查询 where 语句 带上输入内容
guanmingle 2009-11-27
  • 打赏
  • 举报
回复
学习了
qqiuzaihui 2009-11-27
  • 打赏
  • 举报
回复
[Quote=引用 13 楼 jnshijin 的回复:]
我的意思是在Combobox文本框中输入内容时,下拉列表动态过滤内容
[/Quote]
我在8楼不是给你实现了么?
jnshijin 2009-11-27
  • 打赏
  • 举报
回复
自己顶下。别沉下去啊,
jnshijin 2009-11-27
  • 打赏
  • 举报
回复
我的意思是在Combobox文本框中输入内容时,下拉列表动态过滤内容
kinglshadow 2009-11-27
  • 打赏
  • 举报
回复
学习了。。呵呵
jnshijin 2009-11-27
  • 打赏
  • 举报
回复
是在winform中 Combobox,我的意思是在Combobox文本框中输入内容时,下拉列表动态过滤内容。
zcw840421 2009-11-27
  • 打赏
  • 举报
回复
顶一楼和三楼
abaochan 2009-11-27
  • 打赏
  • 举报
回复
BindingSource bind = new BindingSource();
string str2 = "SELECT Top 10 Title, EmployeeID, ReportsTo, PostalCode FROM Employees";
private DataTable GetData(string strSQl)
{
DataTable dtData = new DataTable();
using (SqlConnection thisConnection = new SqlConnection(
@"Data Source=.;Initial Catalog=Northwind;Integrated Security=True"))
{
using (SqlDataAdapter thisAdapter = new SqlDataAdapter(
strSQl, thisConnection))
{
thisAdapter.Fill(dtData);
}
thisConnection.Close();
}
return dtData;
}
private void Form1_Load(object sender, EventArgs e)
{
bind.DataSource = GetData(str2);
this.comboBox1.DisplayMember = "Title";
this.comboBox1.DataSource = bind;
this.comboBox1.Text = string.Empty;
}
private void comboBox1_TextChanged(object sender, EventArgs e)
{
bind.Filter = string.Format("Title Like '{0}%'", this.comboBox1.Text);
this.comboBox1.DroppedDown = true;
}
qqiuzaihui 2009-11-27
  • 打赏
  • 举报
回复
        BindingSource bind = new BindingSource();
string str2 = "SELECT Top 10 Title, EmployeeID, ReportsTo, PostalCode FROM Employees";
private DataTable GetData(string strSQl)
{
DataTable dtData = new DataTable();
using (SqlConnection thisConnection = new SqlConnection(
@"Data Source=.;Initial Catalog=Northwind;Integrated Security=True"))
{
using (SqlDataAdapter thisAdapter = new SqlDataAdapter(
strSQl, thisConnection))
{
thisAdapter.Fill(dtData);
}
thisConnection.Close();
}
return dtData;
}
private void Form1_Load(object sender, EventArgs e)
{
bind.DataSource = GetData(str2);
this.comboBox1.DisplayMember = "Title";
this.comboBox1.DataSource = bind;
this.comboBox1.Text = string.Empty;
}
private void comboBox1_TextChanged(object sender, EventArgs e)
{
bind.Filter = string.Format("Title Like '{0}%'", this.comboBox1.Text);
this.comboBox1.DroppedDown = true;
}
孤剑 2009-11-27
  • 打赏
  • 举报
回复
.net 2.0 以上的,可以使用:
comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
comboBox1.AutoCompleteSource = AutoCompleteSource.ListItems;

.net 1.1 及以下,估计就得自己思考方法了:
最直白的就是1、3楼的方法。

悔说话的哑巴 2009-11-27
  • 打赏
  • 举报
回复
comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
comboBox1.AutoCompleteSource = AutoCompleteSource.ListItems;
风之影子 2009-11-27
  • 打赏
  • 举报
回复
comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
comboBox1.AutoCompleteSource = AutoCompleteSource.ListItems;
jnshijin 2009-11-27
  • 打赏
  • 举报
回复
请高手指出上面代码错误之处。
龙宜坡 2009-11-27
  • 打赏
  • 举报
回复
WinForm Or Web?
jnshijin 2009-11-27
  • 打赏
  • 举报
回复
我的代码:
BindingSource bind = new BindingSource();
DataTable DT;

private void Form3_Load(object sender, EventArgs e)
{
string qq = "select Id,Kind from tb_TableList ";//where Kind like '%" + this.textBox1.Text + "%'";
DataTable DT = MyDataClass.getDataSet(qq).Tables[0];
bind.DataSource = DT;
this.comboBox1.DataSource = bind;
this.comboBox1.DisplayMember = "Kind";
this.comboBox1.ValueMember = "id";
this.comboBox1.Text = string.Empty;
}

private void comboBox1_TextChanged(object sender, EventArgs e)
{
bind.Filter = string.Format("Kind Like '{0}%'", this.comboBox1.Text);
this.comboBox1.DroppedDown = true;

}
加载更多回复(5)

110,536

社区成员

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

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

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