However, I'm using MVVM where I expect aspects like this to be bindable from the ViewModel. Has anyone managed to accomplish what I seek using pure MVVM binding?
10 Answers, 1 is accepted
<RadGridView ... GroupDescriptors="{Binding MyDescriptors}" ... />
System.NotSupportedException: Cannot set read-only property 'Telerik.Windows.Controls.GridView.GridViewDataControl.GroupDescriptors'.
Say it ain't so!
<RadGridView ... local:Grouping.DynamicGroupDescriptor="{Binding MyGroupDescriptor}" ... />
Indeed the GroupDescriptors collection is readonly as we do follow some MS standards and typically will not expose a read write collection typed property.
An MVVM friendly way of controlling the grouping would be to use a CollectionViewSource.View as ItemsSource for the RadGridView. RadGridView will respect the grouping state of the CollectionViewSource.
Kind regards,
Pavel Pavlov
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
Hello,
The grouping with ICollectionView as the ItemsSource is fine. But I did not manage to use an alternate display name (the actual column's header or another string property that is not the group Member). With GroupDescriptors I could use the DisplayContent, but as you said the GroupDescriptors can't be bound to the ViewModel...
Any idea ?
Arnaud.
... and what about the ShowColumnWhenGrouped option ?
Please provide a way to group from ViewModel with respect to the columns definition : Display Header instead of DataMember, Hide column if ShowColumnWhenGrouped is False, etc... Just as if the column was manually group !
Arnaud.
You can try working with QueryableCollectionView and create GroupDescriptor instead. So, you can have the following source collection property in your ViewModel:
private QueryableCollectionView clubs;
public QueryableCollectionView Clubs
{
get
{
if (this.clubs == null)
{
this.clubs = new QueryableCollectionView(Club.GetClubs());
this.clubs.GroupDescriptors.Add(new GroupDescriptor() { Member = "Name", DisplayContent = "CustomName" });
}
return this.clubs;
}
}
Regards,
Maya
Telerik
Hello Maya,
In contrary to ICollectionView the QueryableCollectionView does not support the Filter predicate. The code compiles but the Filter Property raises a runtimeError. Why do you leave it if its not supported ? Could you please help me to filter the QueryableCollectionView ?
Regards,
Arnaud.
You can filter the collection quite easily with the help of FilterDescriptors collection. For example:
private QueryableCollectionView clubs;
public QueryableCollectionView Clubs
{
get
{
if (this.clubs == null)
{
this.clubs = new QueryableCollectionView(Club.GetClubs());
this.clubs.GroupDescriptors.Add(new GroupDescriptor() { Member = "Name", DisplayContent = "CustomName" });
this.clubs.FilterDescriptors.Add(new FilterDescriptor() { Member = "Name", Value = "Arsenal", Operator = FilterOperator.IsEqualTo });
}
return this.clubs;
}
}
In case you want to work with Filter property, you can create your own custom QCV and override it.
Regards,
Maya
Telerik