[RESOLVED] [2.0] ListView refusing to sort
I have a ListView setup with two groups and three columns, one of the groups has 3 ListViewItems under it. I'm sure the items would be in a different order depending on which column you sort on. I implemented a custom class for sorting and wired up an event handler for capturing column clicks. Here's my code:
Code:
private void lvSyncItems_ColumnClick(object sender, ColumnClickEventArgs e)
{
lvSyncItems.ListViewItemSorter = new ListViewSorter(e.Column);
}
private class ListViewSorter : System.Collections.IComparer
{
private int m_ColumnIndex;
public ListViewSorter(int columnIndex)
{
m_ColumnIndex = columnIndex;
}
#region IComparer Members
public int Compare(object x, object y)
{
return String.Compare((x as ListViewItem).SubItems[m_ColumnIndex].Text, (y as ListViewItem).SubItems[m_ColumnIndex].Text);
}
#endregion
}
I have checked the return value from the compare method as the listview is sorting during a column click and everything is correct except the items never get reordered on screen! Does this have something to do with the fact that I'm using groups? Thanks!
Re: [2.0] ListView refusing to sort
Ok, I just set the ShowGroups property to false and it sorts as expected. Please tell me there's a workaround and that this isn't a limitation of the control.
Re: [2.0] ListView refusing to sort
Just so people know, a quick google search reveals that it's a limitation of the underlying control in Windows. It just doesn't know how to sort individual groups. You just have to add the items in sorted order.