Click to See Complete Forum and Search --> : sorting in listview
seljuk
Jun 5th, 2002, 02:57 PM
How can sort a listview control according to its second or third item. (NOT first) for example [name] [number] [class] I want to sort the list using number or class variables. Is there anyone who can help me :rolleyes: :rolleyes: :rolleyes:
Visual basic has sortkey property does c# has any property like this. I find listviewitemsorter property but I didn't understand how can I use it.
DeadTaco
Jun 11th, 2002, 04:35 PM
Here's the way I do it, and it works well.
ListView1.SortOrder = lvwAscending
ListView1.Sorted = True
ListView1.SortKey = 0 '1 = sort by column 1, 2 = sort by column 2, etc.
This will sort the data by the SORTKEY value, where SORTKEY is the column number.
You may want to turn off sorting after the list is sorted, though, since it does funny things with sorting turned on. Sort the data then turn it off.
ListView1.Sorted = False
If you want to sort the data by clicking a column header, place the following code in the ListView_ColumnClick Sub routine...
ListView1.SortOrder = lvwAscending
ListView1.Sorted = True
ListView1.SortKey = ColumnHeader.Index - 1
ListView1.Sorted = False 'Turn off sorting when done
seljuk
Jun 11th, 2002, 05:23 PM
thanks for your your reply I will try it
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.