How to sort ListView items of some column.
-
Hello, my cybrenetics Friends !!! I have a listview, and o wan't to sort the list by clicking the Column header. But i have 2 columns, and i wan't to sort the list by clicking the 2 column, so i can get the items sorted by the second raw. Thanks!!!
One nation - underground
-
Hello, my cybrenetics Friends !!! I have a listview, and o wan't to sort the list by clicking the Column header. But i have 2 columns, and i wan't to sort the list by clicking the 2 column, so i can get the items sorted by the second raw. Thanks!!!
One nation - underground
There are several ways you could do this. But you'll likely want to create an IComparer implementation to look at ListViewItems, or whatever type you stick in the ListViewItem's Tag property. When you add an event handler for the ListView's ColumnClick event, the ColumnClickEventArgs instance gives you the index of the column clicked. You can use that in your IComparer to determine how to sort objects. In your handler, update or create a new comparer and set the ListView's ListViewItemSorter property with the instance you updated or created. Google IComparer to see how to implement one, but it's not difficult.
private void listView1_ColumnClick(object sender, ColumnClickEventArgs e) {
IComparer sorter = new YOURICOMPARER(e.Column)
listView1.ListViewItemSorter = sorter;
listView1.Sort();
}
Try code model generation tools at BoneSoft.com.
-
Hello, my cybrenetics Friends !!! I have a listview, and o wan't to sort the list by clicking the Column header. But i have 2 columns, and i wan't to sort the list by clicking the 2 column, so i can get the items sorted by the second raw. Thanks!!!
One nation - underground