GridViewCustomPropertyProvider support for Grouping by property not Column

2 posts, 0 answers
  1. Steve
    Steve avatar
    124 posts
    Member since:
    Jun 2011

    Posted 09 Aug 2013 Link to this post

    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

  2. Yoan
    Admin
    Yoan avatar
    1070 posts

    Posted 14 Aug 2013 Link to this post

    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 >>
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top