当使用AutoCompleteMode并且模式为Suggest且AutoCompleteSource为ListItems时,Combobox中的C#中存在排序错误。
实施例: Combobox包含项目: “斯维德伯格” “瑞典银行”, “瑞典”
在Combobox中键入“Sw”时,我应该得到两个建议的项目,“Swedbank”和“Swedish”。 问题是只显示了“Swedbank”。 似乎C#将项目排序为: “瑞典银行”, “斯维德伯格” “瑞典”
如果我能使用C#来使用StringComparer.Ordinal,它可以解决问题,因为Ordinal排序看起来效果更好。
关于如何解决这个问题的任何想法?
System.Windows.Forms.ComboBox comboBox1; this.comboBox1 = new System.Windows.Forms.ComboBox(); this.comboBox1.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Suggest; this.comboBox1.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems; this.comboBox1.FormattingEnabled = true; this.comboBox1.Items.AddRange(new object[] { "Svedberg", "Swedbank", "Swedish"}); this.comboBox1.Location = new System.Drawing.Point(142, 474); this.comboBox1.Name = "comboBox1"; this.comboBox1.Size = new System.Drawing.Size(121, 21); this.Controls.Add(this.comboBox1);
答案 0 :(得分:0)
此代码适用于我:
System.Windows.Forms.ComboBox comboBox1;
comboBox1 = new System.Windows.Forms.ComboBox();
comboBox1.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Suggest;
comboBox1.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems;
comboBox1.FormattingEnabled = true;
comboBox1.Items.AddRange(new object[] {
"Svedberg",
"Swedbank",
"Swedish"});
comboBox1.Location = new System.Drawing.Point(0, 0);
comboBox1.Name = "comboBox1";
comboBox1.Size = new System.Drawing.Size(121, 21);
Controls.Add(comboBox1);
我唯一做的就是删除此引用。
此致 微米。