如何通过搜索来建议组合框值

我正在创建一个 Windows 应用程序,并且希望通过筛选用户输入值来显示组合框值。有一个名为属性,但我使用对象为项目分配值。所以我无法填补.如何将我的项目列表分配给它?AutoCompletecomboBoxAutoCompletedSource



ABOUTYOU
浏览 90回答 1
1回答

浮云间

有两种主要方法可以在组合框上自动完成。第一种方法是将源代码设置为 comboBox.Items:&nbsp; &nbsp; &nbsp; &nbsp; comboBox1.AutoCompleteMode = AutoCompleteMode.Suggest;&nbsp; &nbsp; &nbsp; &nbsp; comboBox1.AutoCompleteSource = AutoCompleteSource.ListItems;&nbsp; &nbsp; &nbsp; &nbsp; comboBox1.Items.AddRange(new []{"Omg", "So Kewel"," I love it"});&nbsp;第二种是设置自定义源。在第二种情况下,下拉箭头不会显示任何内容,但自动完成功能会在您开始键入时显示。&nbsp; &nbsp; &nbsp; &nbsp; comboBox1.AutoCompleteMode = AutoCompleteMode.Suggest;&nbsp; &nbsp; &nbsp; &nbsp; comboBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;&nbsp; &nbsp; &nbsp; &nbsp; var list = new List<string>() {"Omg", "So Kewl", "I love it"};&nbsp; &nbsp; &nbsp; &nbsp; var collection = new AutoCompleteStringCollection();&nbsp; &nbsp; &nbsp; &nbsp; collection.AddRange(list.ToArray());&nbsp; &nbsp; &nbsp; &nbsp; comboBox1.AutoCompleteCustomSource = collection;
打开App,查看更多内容
随时随地看视频慕课网APP