uneable to sort my listview
-
I have created a class that inherits from ListView and a class that inherits ListViewItem and implements IComparable. If I put the items in an ArrayList and Sort the items are sorted correctly, but when i try to use Sort in the ListView it doesnt do anything. I´ve tryied invoking the sort part in the listview but no that doesnt work. I do not want to create a class for the sorting part so i thought that IComparable only on the objects in the collection would allow me not to modify the collection. Is there something im missing???
-
I have created a class that inherits from ListView and a class that inherits ListViewItem and implements IComparable. If I put the items in an ArrayList and Sort the items are sorted correctly, but when i try to use Sort in the ListView it doesnt do anything. I´ve tryied invoking the sort part in the listview but no that doesnt work. I do not want to create a class for the sorting part so i thought that IComparable only on the objects in the collection would allow me not to modify the collection. Is there something im missing???
ListView needs an IComparer to be assigned to the ListViewItemSorter property, for the sorting work. Read the help on the Sort property on MSDN for a sample, if your class already implements IComparable, you can simply delegate it to the CompareTo() method, and code the IComparer with one line of code only. And that, IMO is a design mistake, and should be done by the ListView by default. Yes, even I am blogging now!