
Sorted a listview on header click
Private Sub ListView1_ColumnClick(ByVal ColumnHeader As
MSComctlLib.ColumnHeader)
'/* Sort listview based on columnheader clicked
With ListView1
.SortKey = ColumnHeader.Index - 1 '/* key is 0-based, whereas
columnheader is 1 based.
.SortOrder = Abs(Not .SortOrder = 1) '/* this toggles
ascending/descending sorts
.Sorted = True '/* performs the sort
End With
'/* if user wanted to keep the selected
'/* item in view when sorted, do so!
If bKeepVisible Then
If Not ListView1.SelectedItem Is Nothing Then
ListView1.ListItems.Item(ListView1.SelectedItem.Index).EnsureVisible
End If
End If
End Sub
--
Randy Birch
MVP Visual Basic
http://www.mvps.org/vbnet/
Please respond only to the newsgroups so all can benefit.
Quote:
> Hi,
> I would like to know if there is already an existing property , function
or
> sub that sort the listitems of a listview when we click on a header? Do we
> have to code it ourself?
> Thanks
> Zoury