|
-
Dec 19th, 2002, 12:03 AM
#1
Thread Starter
Member
Sorting Columns in Listview
Hi,
I would like to add the functionality of sorting by cliking on the Headings in my ListView. Is this possible?
Does the control take care of this for you? Do you have to code it? How?
-
Dec 19th, 2002, 02:32 AM
#2
Registered User
You can set the Sorting property and then use the Sort method to sort the first column, ascending or descending, if you want more than that you instead have to create you own comparer and set the ListViewItemSorter. If you want an example I created a Comparer to sort dates in any column...
Code:
Class CompareByDate
Implements IComparer
Dim index As Integer
Sub New(ByVal subitemIndex As Integer)
Me.index = subitemIndex
End Sub
Function Compare(ByVal x As Object, ByVal y As Object) As Integer _
Implements System.Collections.IComparer.Compare
Dim item1 As ListViewItem = CType(x, ListViewItem)
Dim item2 As ListViewItem = CType(y, ListViewItem)
Return Date.Compare(Date.Parse(item1.SubItems(index).Text), Date.Parse(item2.SubItems(index).Text))
End Function
End Class
And to use it....
Code:
ListView1.ListViewItemSorter = New CompareByDate(0)
Last edited by Athley; Dec 19th, 2002 at 02:37 AM.
-
Dec 19th, 2002, 04:11 PM
#3
Thread Starter
Member
[resolved]
Thankyou,
I have found a MSDN article entitled:
Sorting ListView Items by Column Using Windows Forms
That explains it pretty well, including code on how to sort by date.
Thanks,
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|