Humbertogo 发表于 2007-9-5 07:50:30

如何对组合框排序?

有没有办法按字母顺序对组合框排序
**** Hidden Message *****

hendie 发表于 2007-9-5 08:02:20

作者未知
Public Function CBsort(CB As ComboBox)
' Sort the Combobox
    Dim CBvar As Variant
    For I = 0 To CB.ListCount - 2
   
      If CB.List(I) > CB.List(I + 1) Then
            CBvar = CB.List(I)
            CB.List(I) = CB.List(I + 1)
            CB.List(I + 1) = CBvar
            I = -1
      End If
    Next I
End Function

Humbertogo 发表于 2007-9-5 08:19:50

在将信息添加到组合框之前对其进行排序。你的代码是什么样子的?你能发一个片段吗?

hendie 发表于 2007-9-5 08:24:29

将项目读入数组、对数组排序然后将数组添加到组合框中可能更容易/更快

Kerry 发表于 2007-9-5 08:32:03


有多少??

Bryco 发表于 2007-9-5 09:22:35

http://vbnet.mvps.org/index.html?code/sort/QS overview . htm
quick sort可能是其中之一,但它需要几秒钟才能确定

hendie 发表于 2007-9-5 09:40:32


有多少

没错
为什么要/需要向组合框中添加9000000项

Keith™ 发表于 2007-9-5 10:06:48

简单的解决方案是在设计时在IDE中将排序属性设置为True
在运行时,组合框排序属性是只读的,因此需要在运行代码之前对其进行设置。

Keith™ 发表于 2007-9-5 13:25:51


但是VBA中的组合框没有用于排序的选项。(除非它被称为其他东西??)

Humbertogo 发表于 2007-9-5 13:30:31

嗯...我最近一直在VB工作...没有考虑到VB和VBA的属性会有所不同...
让我看看我能想出什么
页: [1] 2
查看完整版本: 如何对组合框排序?