Grouping and Sorting in a ListView

by Michael S. Kaplan, published on 2006/03/06 05:01 -05:00, original URI: http://blogs.msdn.com/b/michkap/archive/2006/03/06/544257.aspx


The other day Al asked me via the Contacting Me link:

Hi Michael,

My question has nothing to do with internationalization, but it has something to do with sorting. I hope this makes it interesting enough!

When I group in a ListView, I cannot sort within the groups. Is that a bug?

The ListView class is a managed wrapper around the Shell ListView common control. When you use instances of the ListViewGroup class to set up groupings, the setting of the Sorting property is ignored.

Although at first glance it may look like the native Shell ListView_InsertGroupSorted macro/LVM_INSERTGROUPSORTED message, might be helpful, this is actually referring to sorting between groups, rather than within them....

In practice this can cause real usability problems for very large lists (since one would definitely want to be able to show a large number of items in some kind of sensible order).

The easiest workaround here (unfortunately) seems to be to add them in the correct order.

I am hoping that I am missing something here in either the managed or unmanaged implementations. If I am I won't feel too bad since it's not really one of those 'international' questions, so if you know the answer, don't be shy. :-)

 

This post brought to you by "" (U+1e20, a.k.a. LATIN CAPITAL LETTER G WITH MACRON)


# swautier on 6 Mar 2006 9:47 AM:

My experience with the some of the new features of listview controls such as groups and background images is that they were implemented 'just enough' to fit the Windows Explorer team requirements.

Regarding sorting of grouped lists, it makes sense to me to provide such 'sorted by group' behaviour. But Windows Explorer never really needs it since groups depends on the selected column, hence groups are re-created from scratch each time user clicks a column). Hence sort just plain doesn't work with gropus, although I have not seen it documented anywhere.

Some documented feature(s) are not implemented (such as LVM_MOVEITEMTOGROUP). Some implemented features are not documented (such as watermarks. Thanks Spy++, you saved me...).

Quite a mess, I must say, which is a shame because these advanced listview features are very interesting and help make apps nice. But hadn't I taken it as a challenge to make them work, I would have given up very soon. :-(

Christophe Hannosset on 1 Apr 2010 8:18 PM:

I have been adding groups and list view item in alphabetic order... The groups are at 80% sorted as well as the items. Of course sorting is deactivated...

Apparently the control is reorganizing the group display sequence, I really do not know why but that operation seem to cause the issue...

I did not have e3xperience that previously (maybe lucky....) but also the amount of groups were significantly reduced.


referenced by

2007/05/24 How to do more sorting and grouping by 9am than most ListViews do all day

go to newer or older post, or back to index or month or day