如何对组合框项目进行排序? [英] How to sort Combobox items?
问题描述
我已经在组合框中存储了10个整数项,并且还在属性窗口中设置了属性SORTED = TRUE.
I have stored 10 integer items in combo box and also has set the property SORTED =TRUE in the property window.
在运行时,当我在组合框中查看项目时,它们被列为
And during run time when I view the items in combo box they are listed as
1
10
2
3
4
5
6
7
8
9
因此,第10个值列在第2个位置.
So the 10th value is listed at 2nd position.
任何人都可以告诉我如何解决此问题吗?
Can anyone please tell me how to sort this problem?
预先感谢您
推荐答案
Tabzee,
Tabzee,
问题在于,它会将数字推断为字符串,因此您看到的是字符串排序.
The problem is that it's inferring the numbers as strings and thus what you see is a string sort.
相反,使用实数,对它们进行排序(作为数字),然后添加与这些数字等效的每个字符串,它们将以正确的顺序排列:
Instead, use real numbers, sort them (as numbers) and then add each string equivalent of those numbers and they'll be in the right order:
Option Strict On
Option Explicit On
Option Infer Off
Public Class Form1
Private Sub Form1_Load(sender As System.Object, _
e As System.EventArgs) _
Handles MyBase.Load
Dim numbers As IEnumerable(Of Integer) = Enumerable.Range(1, 10)
Using combo As New ComboBox
For Each i As Integer In numbers
combo.Items.Add(i.ToString)
Next
End Using
Stop
End Sub
End Class
在那种情况下,我不必对它们进行排序,但希望您能理解.
In that one, I don't have to sort them, but hopefully you get the idea.
这篇关于如何对组合框项目进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!