this.cmbCategory.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Suggest;
this.cmbCategory.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems;
this.cmbCategory.DropDownStyle = ComboBoxStyle.DropDown;
this.cmbCategory.Tag = new List<string>(gridStyle.ColumnDatas.FirstOrDefault(o => o.Name == "StartingStation").Dependency.FirstOrDefault(o => o.Name == "Category").Values);
this.cmbCategory.Items.AddRange(((List<string>)this.cmbCategory.Tag).ToArray());
您好 :
谢谢您好的帮助,我有如下问题:
this.cmbCategory.Tag = new List<string>(gridStyle.ColumnDatas.FirstOrDefault(o => o.Name == "StartingStation").Dependency.FirstOrDefault(o => o.Name == "Category").Values);
这句当中的gridStyle是从哪引用的?
@furenjian: 我随便从我的代码中摘取了一行:
this.cmbCategory.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Suggest;
this.cmbCategory.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems;
this.cmbCategory.DropDownStyle = ComboBoxStyle.DropDown;
这些代码是你要设置的,然后你需要指定候选列表的数据是什么:
this.cmbCategory.Items.AddRange(new string[]{"dfd","d","df","df"});
也就是说你启用了AutoCompleteMode后,你输入字符时,它会自动从 this.cmbCategory.Items 去寻找匹配的项目。
@Launcher:
您好,谢谢。我combox绑定的是数据库datasource,字母和数字能自动匹配,汉字还不行.
@furenjian: 汉字也可以,this.cmbCategory.Items.AddRange(new string[]{"中文","d","df","df"}); 匹配不是从绑定源读取的,是从 Items 中读取的。
给combox加键盘事件