Update postings on Datagrid
Recently I wrote two posts on the Silverlight Datagrid:
- Synchronizing group row headers with column headers in Silverlight DataGrid
- Drag and Drop grouping in Datagrid
Andy noticed that in a comment that the synchronizing of the group row headers with the column headers did not work correctly when the group headers were scrolled out of view and then back into view again.
After investigating the reason of this behavior I have decided to take another approach and to re-implement this functionality. Some additional testing of this new implementation reveals that the issue reported by Andy has been solved. The only quirk now is that whenever the short description of the Display attribute is set on a property of the data and the Header of the column is explicitly set, the column will show the header and the group row the short descriptions.
This new approach to synchronizing the group headers with the column headers is now also used in the implementation of the Drag and Drop grouping. As it turned out, this synchronizing approach simplified the implementation of Drag and drop grouping, because the cloning of the CollectionView was not needed anymore. Also after applying the grouping the selected elements would still be selected.
Finally some additional changes have been made:
- A dialog for selecting columns has been added
- Reordering of the groups is supported
- The column by which is grouped is automatically hidden
- The components are wrapped in a reusable DLL
The modified code can be downloaded here.
Update
The code from this post has been updated. A newer version can be downloaded from here

Lars Morten Nygaard said:
Nov 11, 10 at 5:01 pmHi – thanks for a great post.
I have a question, related to the use of PCV and Datagrid grouping.
My goal is to determine the “Selected group(s)”, and to convey this to my VM. The VM will then delete them from the PagedCollectionView.
Option 1:
I’m using a re-styled DataGridRowGroupHeader with some additional text, and a checkbox.
The reason for the check-box is to be able to select a number of “groups”, and delete them from the PagedCollectionView in my VM.
I’m getting everything set up right, but when I’ve checked a couple of boxes, I cannot find a way to determine which groupheaders have been checked.
Option 2:
Another approach I have tried is having a delete button in each group header. When the button is pressed, it should fire a delete command in my VM indicating that the current group is to be deleted. The only thing I need to know in my VM is what group is selected, or even what is the PCV.CurrentItem assosiated with this group.
My problem of course is that by selecting the GroupHeader (with or without expanding it), I’m apparently not setting the CurrentItem in the PCV.
Any ideas on how to approach this using my own, or a completely different approach?
LarsM
Emiel said:
Nov 13, 10 at 9:38 pmThis is a tough question to answer. The biggest problem is the UI virtualization (see for instance this article).
Probably the best route to go is to maintain a separate collection of which checkboxes are checked and keep this collection up to date. This collection can also be used to make sure that the correct checkboxes are checked whenever a group header is recycled.
So unfortunately: no out-of-the-box solution from me…