这个Combobox已经绑定了数据库的资料:
例如有: 
A1 
A2 
B1 
B2 
C1 
C2 
当我输入C的时候Combobox下拉列表绑定C1,C2,就是用输入的关键字模糊下拉出相应的内容,类似于Google搜索的下拉效果 。
多谢各位!

解决方案 »

  1.   


     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;
      

  2.   

    comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
    comboBox1.AutoCompleteSource = AutoCompleteSource.ListItems;http://topic.csdn.net/u/20090326/22/c0881663-3fb7-4dca-ad09-b7ff2064d497.html
      

  3.   


    //取得绑定的表
    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();
    }
      

  4.   

    comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend; 
    comboBox1.AutoCompleteSource = AutoCompleteSource.ListItems; 
      

  5.   

    .net 2.0 以上的,可以使用:
    comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend; 
    comboBox1.AutoCompleteSource = AutoCompleteSource.ListItems; .net 1.1 及以下,估计就得自己思考方法了:
    最直白的就是1、3楼的方法。
      

  6.   

            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;
            }
      

  7.   

    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;
            }
      

  8.   

    是在winform中 Combobox,我的意思是在Combobox文本框中输入内容时,下拉列表动态过滤内容。
      

  9.   

    我的意思是在Combobox文本框中输入内容时,下拉列表动态过滤内容
      

  10.   

    我按我理解的楼主的意思 应该这样解
    Combobox输入内容时 重新绑定数据源 带上模糊查询 where 语句 带上输入内容
      

  11.   

    被楼主头像吸引了1,2楼可解决问题若如 16楼所说,给 控件添加 onKeyPress  事件可解决!每次输入字符都 触发,去处理 
      

  12.   

    我已经重新封装了,你下载就可以使用了,支持汉字的声母查询,结局了在tablelayout内部的问题。
    http://download.csdn.net/source/1795800
      

  13.   

    comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend; 
    comboBox1.AutoCompleteSource = AutoCompleteSource.ListItems
      

  14.   


    我试了,报错:InvalidArgument=“0”的值对于“SelectedIndex”无效。
    参数名: SelectedIndex
      

  15.   

    我的代码:
    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;        }
      

  16.   

    comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend; 
    comboBox1.AutoCompleteSource = AutoCompleteSource.ListItems; 
      

  17.   

                this.comboBox1.DisplayMember = "Kind"; 
                this.comboBox1.ValueMember = "id"; 
                this.comboBox1.Text = string.Empty;
                this.comboBox1.DataSource = bind;