C# 将项目列表添加到按字符串排序的组合框不自然
我使用此代码向组合框添加数字,
for (int i = 15; i < 250; i++)
{
cbSumFrom.Items.Add(i);
}
问题是我得到类似的内容
100
101
......
,但我想
15
16
17
......
如何修复它?
i use this code to add a numbers to combobox
for (int i = 15; i < 250; i++)
{
cbSumFrom.Items.Add(i);
}
the problem is that i get something like
100
101
......
but i want like
15
16
17
......
how to fix it ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
问题是,组合框似乎正在对项目进行排序,并且它正在对每个字符进行 ASCII 比较来执行此操作,因此 100 在 15 之前,因为 10 在 15 之前。取消组合框的排序,它应该列出它们按照您添加它们的顺序
The problem is is that it appears the combo box is sorting the item and it's doing an ASCII comparison on each character to do it, so 100 comes before 15 because 10 is before 15. Take the sorting off the combo box and it should list them in the order you;ve added them
查看您的
ComboBox.Sorted
属性。如果它是 True ,那么您会得到不需要的行为(默认,基于字符串的排序)。由于您是从看起来像预排序列表的内容填充组合框,请确保 ComboBox.Sorted 设置为False
。Take a look at your
ComboBox.Sorted
property. If it isTrue
then you get your unwanted behavior (default, string-based sort.) Since you are populating the combo box from what looks like a presorted list, make sure thatComboBox.Sorted
is set toFalse
.试试这个...没有测试过,但试试这个...
Try this...didn't tested it but try this...