基于值列表访问列表框 - 按列排序
Posted
技术标签:
【中文标题】基于值列表访问列表框 - 按列排序【英文标题】:Access Listbox based on value list - sorting on column 【发布时间】:2011-10-12 10:42:31 【问题描述】:我在访问表单上有一个包含 3 列的列表框,它的行源是一个值列表(不是来自数据库的记录集),它作为逗号分隔的字符串传递。第三列是一个数值,我希望对第三列的列表框 desc 进行排序。
行源如下所示:
0,Standard price,1650,
14,Bookings made during Oct 2011,3770,
15,Minimum Stay 4 Nights - Special Price,2460
列表框正确填充。在这种情况下,我只是不知道如何按第三列对列表框进行排序。有什么想法吗?
【问题讨论】:
【参考方案1】:使用断开连接记录集的一个非常粗略的想法:
Dim rs As New ADODB.Recordset
slist = "0,Standard price,1650," _
& "14,Bookings made during Oct 2011,3770," _
& "15,Minimum Stay 4 Nights - Special Price,2460"
With rs
.ActiveConnection = Nothing
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockBatchOptimistic
With .Fields
.Append "Field1", adInteger
.Append "Field2", adVarChar, 200
.Append "Field3", adInteger
End With
.Open
ary = Split(slist, ",")
For j = 0 To UBound(ary)
.AddNew
For i = 0 To 2
.Fields(i).Value = ary(j)
j = j + 1
Next
j = j - 1
Next
.Sort = "Field3"
End With
slist = rs.GetString(, , ",", ",")
slist = Left(slist, Len(slist) - 1)
【讨论】:
哇,效果很好。我能够利用您的代码来实现我的目标。谢谢以上是关于基于值列表访问列表框 - 按列排序的主要内容,如果未能解决你的问题,请参考以下文章