我做了个winform程序,事先将combobox的items与数据库里的一张表的一列绑定,但是这列里项数太多,我想实现在我向combobox中输入内容时下拉菜单能自动弹出,并且下拉菜单里的项能与我输入的内容自动匹配。请高手指教。

解决方案 »

  1.   


    DataTable dt = new DataTable();
    dt.Columns.Add("Name");
    dt.Columns.Add("VV");
    dt.Rows.Add(new string[] { "王一", "x" });
    dt.Rows.Add(new string[] { "赵一", "z" });
    dt.Rows.Add(new string[] { "王二", "y" });
    dt.Rows.Add(new string[] { "赵二", "w" });this.comboBox1.DataSource = dt;
    this.comboBox1.DisplayMember = "Name";
    this.comboBox1.ValueMember = "VV";
    this.comboBox1.AutoCompleteSource = AutoCompleteSource.ListItems;
    this.comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
      

  2.   

    ComboBox.AutoCompleteMode=AutoCompleteMode.Suggest;
    ComboBox.AutoCompleteSource=AutoCompleteSource.CustomSource;
    ComboBox.AutoCompleteCustomSource=字符串集合。
      

  3.   

    http://www.codeproject.com/KB/WPF/MultiComboBox.aspx
      

  4.   


    string cbxText = "";
    private void comboBox1_TextChanged(object sender, EventArgs e)
            {
                string temp = comboBox1.Text;
                if (temp.Length > 3 && temp.IndexOf("-").Equals(2))
                {            }
                else
                {
                    cbxText = comboBox1.Text;                if (comboBox1.Text.Length == cbxText.Length - 1)
                    {
                        this.cbxText = "";
                        this.comboBox1.Text = "";
                    }
                    else
                    {
                        //this.comboBox1.Items.Clear();
                        string sql = "";
                        if (comboBox1.Text != "")
                        {                        sql = string.Format("select  车号编号,车牌号 from 车号表 where 车牌号 like('___{0}%')", this.comboBox1.Text);
                            DataTable dt = db.GetDataTable(sql);
                            this.comboBox1.DroppedDown = true;
                            this.comboBox1.DataSource=dt;
                            this.comboBox1.SelectedIndex = -1;
                            this.comboBox1.DisplayMember = "车牌号";
                            this.comboBox1.ValueMember = "车号编号";
                            
                            comboBox1.Text = cbxText;
                            comboBox1.Select(cbxText.Length, cbxText.Length);
                        }
                    }            }        }