views:

324

answers:

1

Given a Silverlight 3 datagrid that contains groups which are closed, when a row sort is initiated by clicking on a column header, all closed groups open to show their contents. Is there any way to stop this from happening?

I'm using Silverlight 3 with the July 2009 toolkit.

A: 

I wrote an extension method for the DataGrid:

    public static void CollapseAllGroups(this DataGrid dataGrid) {
        dataGrid.Dispatcher.BeginInvoke(delegate {
            var cv = dataGrid.ItemsSource as ICollectionView;
            if (cv != null && cv.Groups != null) {
                foreach (CollectionViewGroup groupname in cv.Groups) {
                    dataGrid.CollapseRowGroup(groupname, true);
                }
            }
        });
    }

In my case I hook it to the underlying DomainDataSource's DataLoaded event.

Marc Wittke