|
-
Sep 5th, 2006, 08:36 AM
#1
Thread Starter
Fanatic Member
[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!
The human brain cannot hold all of the knowledge that exists in this world, but it can hold pointers to that knowledge.
-
Sep 5th, 2006, 08:39 AM
#2
Thread Starter
Fanatic Member
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.
The human brain cannot hold all of the knowledge that exists in this world, but it can hold pointers to that knowledge.
-
Sep 7th, 2006, 05:14 PM
#3
Thread Starter
Fanatic Member
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.
The human brain cannot hold all of the knowledge that exists in this world, but it can hold pointers to that knowledge.
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
|