|
-
Jan 14th, 2012, 01:13 PM
#1
Thread Starter
New Member
Simple Question About Sorting a ListView
Okay, so I have an application that has a listview on it that I have set to sort column based on clicking a column header. I'm using the ColumnSort class from MSDN with this code in the form class:
Code:
Private Sub lstGroup1_ColumnClick(ByVal sender As Object, ByVal e As System.Windows.Forms.ColumnClickEventArgs) Handles lstGroup1.ColumnClick
' Determine if the clicked column is already the column that is
' being sorted.
If (e.Column = lvwColumnSorter.SortColumn) Then
' Reverse the current sort direction for this column.
If (lvwColumnSorter.Order = SortOrder.Ascending) Then
lvwColumnSorter.Order = SortOrder.Descending
Else
lvwColumnSorter.Order = SortOrder.Ascending
End If
Else
' Set the column number that is to be sorted; default to ascending.
lvwColumnSorter.SortColumn = e.Column
lvwColumnSorter.Order = SortOrder.Ascending
End If
' Perform the sort with these new sort options.
Me.lstGroup1.Sort()
End Sub
Now, this form has 13 different listviews on it that serve different functions and I am moving items between these listviews quite frequently. The problem I am running into is that if I have items sorted in a listview, I move some of the first items to a different listview and (for any given reason) move them back to the first, it tacks them on at the end, out of order.
( I have 1,2,3,4,5 in LV1 and move 1,2,3 to LV2 so I have: 1,2,3 in LV2 and 4,5 in LV1. Move 1,2,3 back to LV1 and it comes out 4,5,1,2,3 in LV1.)
Of course, I can just click the column headers to resort them, but with how much transferring is going on, that could be an awful lot of column clicks. So what I would like to do is sort the listviews, automatically in code, each time one of these transfers is made.
I apologize if this question has been answered (and it probably has) but it seems everyone I search wants to sort a listview on column click instead of what I need.
So, if I want to do this automatically, I can either modify the code above to handle it by changing e to what I need, or I can call the code above each time I need it by calling the event and passing the sender and e values to it. I would prefer the first option though. So my question is rather simple (I hope) if I put the sort method into its own sub, what do I substitute for e.Column to make this work automatically?
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
|