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...
In the RestoreValueMethod....
Best,
Steve
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