|
对窗体的更改
通常情况下,要在升序和降序排序之间切换,您要多次单击列标题。用户期望如果他们单击列标题,排序将会发生,随后再次单击将更改排序顺序。前面的代码示例需要能够确定何时多次单击列。为此,您可以将一个私有整数变量添加到 Form 类。这个变量存储上一次单击的列。ColumnClick 事件处理方法将使用这个变量来比较上一次的列与当前单击的列,并确定它们是否相同。将以下成员定义添加到 Form 类中。
''''Visual Basic
Dim sortColumn as Integer = -1
//C#
private int sortColumn = -1;
ColumnClick 事件处理方法的更改
在前面的示例中定义的 ColumnClick 事件处理方法需要进行修改,以便跟踪单击过的列和当前排序顺序。添加以下代码以替换在前面的示例中创建的 ColumnClick 事件处理方法中的代码。
''''Visual Basic
Private Sub listView1_ColumnClick(sender As Object, e As
System.Windows.Forms.ColumnClickEventArgs)
'''' Determine whether the column is the same as the last column clicked.
If e.Column <> sortColumn Then
'''' Set the sort column to the new column.
sortColumn = e.Column
'''' Set the sort order to ascending by default.
listView1.Sorting = SortOrder.Ascending
Else
'''' Determine what the last sort order was and change it.
If listView1.Sorting = SortOrder.Ascending Then
listView1.Sorting = SortOrder.Descending
Else
listView1.Sorting = SortOrder.Ascending
End If
End If
'''' Call the sort method to manually sort.
listView1.Sort()
'''' Set the ListViewItemSorter property to a new ListViewItemComparer
'''' object.
listView1.ListViewItemSorter = New ListViewItemComparer(e.Column, _
listView1.Sorting) 上一页 [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老了 微软开发新邮件客户端取而代之_联络工具
|