Answered by:
How to sort multiple listview on a form

Question
-
I have several listview's on a form and would like to add this event to each listview to allow sorting:
What changes are need to make this a common event?
Thanks in advance
private void lstFG_ColumnClick(object sender, ColumnClickEventArgs e) { // Determine if clicked column is already the column that is being sorted. if (e.Column == lvwColumnSorter.SortColumn) { // Reverse the current sort direction for this column. if (lvwColumnSorter.Order == SortOrder.Ascending) { lvwColumnSorter.Order = SortOrder.Descending; } else { lvwColumnSorter.Order = SortOrder.Ascending; } } else { // Set the column number that is to be sorted; default to ascending. lvwColumnSorter.SortColumn = e.Column; lvwColumnSorter.Order = SortOrder.Ascending; } // Perform the sort with these new sort options. this.lstFG .Sort(); }
Answers
-
this.lstFG .Sort();
change this to cast the Object Sender to the listview...
((ListView)lstFG).Sort();
The control that fires the event is represented by the object 'sender'.
- Proposed as answer by Leo Liu - MSFT Monday, December 27, 2010 8:11 AM
- Marked as answer by Leo Liu - MSFT Wednesday, December 29, 2010 9:41 AM
-
- Proposed as answer by Leo Liu - MSFT Monday, December 27, 2010 8:11 AM
- Marked as answer by Leo Liu - MSFT Wednesday, December 29, 2010 9:41 AM
All replies
-
this.lstFG .Sort();
change this to cast the Object Sender to the listview...
((ListView)lstFG).Sort();
The control that fires the event is represented by the object 'sender'.
- Proposed as answer by Leo Liu - MSFT Monday, December 27, 2010 8:11 AM
- Marked as answer by Leo Liu - MSFT Wednesday, December 29, 2010 9:41 AM
-
- Proposed as answer by Leo Liu - MSFT Monday, December 27, 2010 8:11 AM
- Marked as answer by Leo Liu - MSFT Wednesday, December 29, 2010 9:41 AM