winform中Combobox模糊下拉 这个Combobox已经绑定了数据库的资料:例如有: A1 A2 B1 B2 C1 C2 当我输入C的时候Combobox下拉列表绑定C1,C2,就是用输入的关键字模糊下拉出相应的内容,类似于Google搜索的下拉效果 。多谢各位! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 DataSet ds = new DataSet();//这个DataSet是你从数据库里取出来的值 string[] arr = new string[ds.Tables[0].Rows.Count]; for (int i = 0; i < arr.Length; i++) { arr[i] = ds.Tables[0].Rows[i][2].ToString(); } textBox1.AutoCompleteCustomSource.AddRange(arr); textBox1.AutoCompleteSource = AutoCompleteSource.CustomSource; textBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend; comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;comboBox1.AutoCompleteSource = AutoCompleteSource.ListItems;http://topic.csdn.net/u/20090326/22/c0881663-3fb7-4dca-ad09-b7ff2064d497.html //取得绑定的表DataTable datSource=Combobox.DataSource.Copy();//在comboBox1的TextChanged处理private void comboBox1_TextChanged(object sender, EventArgs e){ //设置条件 string strSql="列值 like '"+comboBox1.Text.ToString()+"%'"; //定义视图取得符合条件的行数. DataView davTemp = new DataView(datSource,strSql,string.Empty,DataViewRowState.CurrentRows); this.comboBox1.DataSource=davTemp.ToTable();} comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend; comboBox1.AutoCompleteSource = AutoCompleteSource.ListItems; .net 2.0 以上的,可以使用:comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend; comboBox1.AutoCompleteSource = AutoCompleteSource.ListItems; .net 1.1 及以下,估计就得自己思考方法了:最直白的就是1、3楼的方法。 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; } 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; } 是在winform中 Combobox,我的意思是在Combobox文本框中输入内容时,下拉列表动态过滤内容。 我的意思是在Combobox文本框中输入内容时,下拉列表动态过滤内容 我按我理解的楼主的意思 应该这样解Combobox输入内容时 重新绑定数据源 带上模糊查询 where 语句 带上输入内容 被楼主头像吸引了1,2楼可解决问题若如 16楼所说,给 控件添加 onKeyPress 事件可解决!每次输入字符都 触发,去处理 我已经重新封装了,你下载就可以使用了,支持汉字的声母查询,结局了在tablelayout内部的问题。http://download.csdn.net/source/1795800 comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend; comboBox1.AutoCompleteSource = AutoCompleteSource.ListItems 我试了,报错:InvalidArgument=“0”的值对于“SelectedIndex”无效。参数名: SelectedIndex 我的代码: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; } comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend; comboBox1.AutoCompleteSource = AutoCompleteSource.ListItems; this.comboBox1.DisplayMember = "Kind"; this.comboBox1.ValueMember = "id"; this.comboBox1.Text = string.Empty; this.comboBox1.DataSource = bind; 未将对象引用设置到对象的实例--连接数据库时出现异常的解决办法 c#从数据表中读取数据然后形成树的代码??? 一组动态生成的Label控件显示投票数,为什么显示的票数不更新? C#做的COM如何被其它语言调用?如DELPHI,涉及到数据类型. DataGridTextboxColumn的问题,负数的问题 在XP下与pocket pc的连接问题 如何快速在局域网内建立 socket 连接? 用C#作script为什么没有效果? 如何做个tabcontrol用户控件 有关 NotifyIcon 操作系统中的资源指的是什么 indexof问题
DataSet ds = new DataSet();//这个DataSet是你从数据库里取出来的值
string[] arr = new string[ds.Tables[0].Rows.Count];
for (int i = 0; i < arr.Length; i++)
{
arr[i] = ds.Tables[0].Rows[i][2].ToString();
} textBox1.AutoCompleteCustomSource.AddRange(arr);
textBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;
textBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
comboBox1.AutoCompleteSource = AutoCompleteSource.ListItems;http://topic.csdn.net/u/20090326/22/c0881663-3fb7-4dca-ad09-b7ff2064d497.html
//取得绑定的表
DataTable datSource=Combobox.DataSource.Copy();
//在comboBox1的TextChanged处理
private void comboBox1_TextChanged(object sender, EventArgs e)
{
//设置条件
string strSql="列值 like '"+comboBox1.Text.ToString()+"%'";
//定义视图取得符合条件的行数.
DataView davTemp = new DataView(datSource,strSql,string.Empty,DataViewRowState.CurrentRows);
this.comboBox1.DataSource=davTemp.ToTable();
}
comboBox1.AutoCompleteSource = AutoCompleteSource.ListItems;
comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
comboBox1.AutoCompleteSource = AutoCompleteSource.ListItems; .net 1.1 及以下,估计就得自己思考方法了:
最直白的就是1、3楼的方法。
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;
}
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;
}
Combobox输入内容时 重新绑定数据源 带上模糊查询 where 语句 带上输入内容
http://download.csdn.net/source/1795800
comboBox1.AutoCompleteSource = AutoCompleteSource.ListItems
我试了,报错:InvalidArgument=“0”的值对于“SelectedIndex”无效。
参数名: SelectedIndex
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; }
comboBox1.AutoCompleteSource = AutoCompleteSource.ListItems;
this.comboBox1.ValueMember = "id";
this.comboBox1.Text = string.Empty;
this.comboBox1.DataSource = bind;