VBGood网站全文搜索 Google

首页 - 经验之谈 - 添加一个栏目类别到VB的ListView中
发表评论(0)作者:John Hodgson, 平台:VB6.0+Win98, 阅读:13037, 日期:2001-03-08
Add a column sort feature to VB注释:s ListView

In programs such as Outlook and Windows Explorer, you can sort the
contents of a ListView control by clicking on the column headers.
The sort order toggles between ascending and descending. To achieve
this functionality, place the following code in a standard module:

Public Sub SortListView(ByVal lvw As MSComctlLib.ListView, _
     ByVal colHdr As MSComctlLib.ColumnHeader)
注释:--set the sortkey to the column header注释:s index - 1
lvw.SortKey = colHdr.Index - 1
lvw.Sorted = True

注释:--toggle the sort order between ascending & descending
lvw.SortOrder = 1 Xor lvw.SortOrder
End Sub

The final line of this code toggles the sort order of the listview
between the enumerated listsortorder constants lvwAscending (0) and
lvwDescending (1) each time the procedure is called. This provides
the functionality that reverses the sort order each time the user
clicks the column header.

To call this procedure, use the Listview注释:s Column_Click() event as follows:

Private Sub lvwMyListView_ColumnClick(ByVal ColumnHeader As _
SortListView lvwMyListView, ColumnHeader
End Sub

Tip contributed by John Hodgson, ClickSmart Technologies, jrhodgson@bigpond.com.au