日期:2014-05-18  浏览次数:21325 次

ComboBox中输入文字匹配自动检索匹配数据 在线等!c#
意思是:假如我的ComboBox的list中有abcd, abde, acdf等等项目。如果我开始输入a,combobox应当立即显示abcd,并且,bcd是选中状态,以便用户继续输入。如果第二个输入c,则马上显示acdf,并且df是选中状态。我说的combobox是dropdown样式的。


------解决方案--------------------
C# code

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

------解决方案--------------------
this.comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
this.comboBox1.AutoCompleteSource = AutoCompleteSource.ListItems;

------解决方案--------------------
C# code
private void comboBox1_TextChanged(object sender, EventArgs e)
        {
            string str = this.comboBox1.Text;
            for (int i = 0; i < this.comboBox1.Items.Count; i++)
            {
                if (this.comboBox1.Items[i].ToString().IndexOf(str) == 0)
                {
                    this.comboBox1.Text = this.comboBox1.Items[i].ToString();
                    this.comboBox1.Select(str.Length, this.comboBox1.Text.Length - str.Length);
                    break;
                }
            }
        }

------解决方案--------------------
探讨
C# code
this.comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
this.comboBox1.AutoCompleteSource = AutoCompleteSource.ListItems;

------解决方案--------------------
探讨
C# code
this.comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
this.comboBox1.AutoCompleteSource = AutoCompleteSource.ListItems;

------解决方案--------------------
探讨
C# code
this.comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
this.comboBox1.AutoCompleteSource = AutoCompleteSource.ListItems;