|
性的对象。正如这个示例的后面部分所示,ListViewItemComparer 类包含一个指定排序顺序的新参数。您使用 ListView.Sorting 属性的值,将值分配给该参数。
ListViewItemComparer 类的更改
使该示例可以以升序或降序进行排序的上面的一系列更改就是对 ListViewItemComparer 类的更改。增加的代码将执行以两种排序模式之一比较项目所需的逻辑。添加以下代码以替换在前面的示例中为 ListViewItemComparer 定义的代码。
''''Visual Basic
'''' Implements the manual sorting of items by columns.
Class ListViewItemComparer
Implements IComparer
Private col As Integer
Private order as SortOrder
Public Sub New()
col = 0
order = SortOrder.Ascending
End Sub
Public Sub New(column As Integer, order as SortOrder)
col = column
Me.order = order
End Sub
Public Function Compare(x As Object, y As Object) As Integer _
Implements System.Collections.IComparer.Compare
Dim returnVal as Integer = -1
returnVal = [String].Compare(CType(x, _
ListViewItem).SubItems(col).Text, _
CType(y, ListViewItem).SubItems(col).Text)
'''' Determine whether the sort order is descending.
If order = SortOrder.Descending Then
'''' Invert the value returned by String.Compare.
returnVal *= -1
End If
上一页 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] 下一页 [系统软件]windows下Apache+php+mysql的安装与配置图解 [Web开发]VB的窗体布局窗口为什么找不到窗体的Form1小图标 [电脑技术]UNformAT恢复格式化命令介绍 [操作系统]在Windows中玩转Linux操作系统 [操作系统]死马还当活马医:6种方法挽救Windows系统 [聊天工具]四大更新 Windows Live Msn 8.1评测 [聊天工具]Windows Live Messenger最新0683版亮相_联络工具_… [聊天工具]Windows Live Mail招人爱的N个理由_联络工具_Wind… [聊天工具]Windows Live Mail Desktop多图欣赏_联络工具_Win… [聊天工具]OE老了 微软开发新邮件客户端取而代之_联络工具
|