《我的编程笔记》C#篇-comboBox与textBox搜索提示功能

comboBox和textBox支持内置的搜索提示功能,在form的InitializeComponent()中添加如下语句:

//将数据添加到搜索范围
this.comboBox1.AutoCompleteCustomSource.AddRange(new string[] { "10.152.154.89", "10.152.154.90", "10.152.252.10", "10.152.252.11" });
//设定comboBox完成内置的搜索,默认是None,还有Append,和SuggestAppend属性,除了默认的None都可以实现搜索提示的功能,只是外观有所不同而已
 this.comboBox1.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend;
//制定搜索范围
 this.comboBox1.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.Allurl;

注:如果comboBox1有数据源,可以直接用AutoCompleteSource.ListItems;

 

        public Form1()//自动提示
        {
            InitializeComponent();
            this.comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
            this.comboBox1.AutoCompleteSource = AutoCompleteSource.ListItems;
        }

你可能感兴趣的:(编程,String,C#,textbox)