This is a migrated thread and some comments may be shown as answers.

GridViewCustomPropertyProvider support for Grouping by property not Column

1 Answer 58 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Steve
Top achievements
Rank 1
Steve asked on 09 Aug 2013, 08:45 PM
Hi all,
I ran into a situation where I programmatically grouped my Grid by a property that was not a column on the Grid using a GroupDescriptor.  It worked fine of course until I tried to persist it.  The GridViewCustomPropertyProvider.cs that I downloaded from Telerik many moons ago expected ColumnGroupDescriptors only.  After some investigation I found that I had to make modifications to support both types.  I share the code here in case someone else also needs this support.

In the ProvideValue method...
case "GroupDescriptors":
    {
        List<GroupDescriptorProxy> groupDescriptorProxies = new List<GroupDescriptorProxy>();
 
        foreach (GroupDescriptorBase descriptor in gridView.GroupDescriptors)
        {
            if (descriptor is GroupDescriptor)
            {
                groupDescriptorProxies.Add(new GroupDescriptorProxy()
                {
                    ColumnUniqueName = (descriptor as GroupDescriptor).Member,
                    SortDirection = descriptor.SortDirection,
                });
            }
            else if (descriptor is ColumnGroupDescriptor)
            {
                groupDescriptorProxies.Add(new GroupDescriptorProxy()
                {
                    ColumnUniqueName = (descriptor as ColumnGroupDescriptor).Column.UniqueName,
                    SortDirection = descriptor.SortDirection,
                });
            }
 
        }
 
        return groupDescriptorProxies;
    }

In the RestoreValueMethod....
case "GroupDescriptors":
    {
        gridView.GroupDescriptors.SuspendNotifications();
 
        gridView.GroupDescriptors.Clear();
 
        List<GroupDescriptorProxy> groupDescriptorProxies = value as List<GroupDescriptorProxy>;
 
        foreach (GroupDescriptorProxy proxy in groupDescriptorProxies)
        {
            GridViewColumn column = gridView.Columns[proxy.ColumnUniqueName];
            GroupDescriptorBase gd = null;
            if (column != null)
            {
                gd = new ColumnGroupDescriptor()
                {
                    Column = column,
                    SortDirection = proxy.SortDirection
                };
            }
            else // assume GroupDescriptor
            {
                gd = new GroupDescriptor()
                {
                    Member = proxy.ColumnUniqueName,
                    SortDirection = proxy.SortDirection
                };
            }
            gridView.GroupDescriptors.Add(gd);
        }
 
        gridView.GroupDescriptors.ResumeNotifications();
    }





Best,
Steve

1 Answer, 1 is accepted

Sort by
0
Yoan
Telerik team
answered on 14 Aug 2013, 01:49 PM
Hi Steve,

I am glad to hear that you have solved your problem. Thank you for sharing your solution to the community. 

Regards,
Yoan
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
GridView
Asked by
Steve
Top achievements
Rank 1
Answers by
Yoan
Telerik team
Share this question
or