Hi,
I've got a problem with a GroupDescriptor with a AggregateFunction defined in xaml as follows:
<
telerik:RadGridView.GroupDescriptors
>
<
telerik:GroupDescriptor
Member
=
"OutputType"
SortDirection
=
"Ascending"
>
<
telerik:GroupDescriptor.AggregateFunctions
>
<
telerik:CountFunction
Caption
=
"Entries count: "
/>
</
telerik:GroupDescriptor.AggregateFunctions
>
</
telerik:GroupDescriptor
>
</
telerik:RadGridView.GroupDescriptors
>
When the grid is first loaded everything works as expected, that is each group has it's correct Entries count value but if I change a rows "OutputType" so that so that it moves to another group then the group to where the item gets added to gets a new Entries count but the group from where that row was removed from still has the oldvalue in the entries count.
Example
The grid is grouped on OutputType which has two groups; OutputType1 and OutputType2
Visual state of the gridview at intial load:
OutputType1 Entries count: 3
OutputType2 Entries count: 4
Edit a row with OutputType1 and change it's value to OutputType2
Visual state of the gridview after edit:
OutputType1 Entries count: 3
OutputType2 Entries count: 5
So the increment count on OutputType2 works as expected but OutputType1 is not decremented accordingly.
Please advice
Tomas
15 Answers, 1 is accepted
May you provide a bit more details about your settings, mainly about the type of the source for the grid ? Furthermore, may you try out your application with the assemblies from our Latest Internal Build ?
Maya
the Telerik team

Thanks for the quick reply.
The grids ItemsSource is bound to a RadDataPager which in turn is bound to a property in my ViewModel exposed as IEnumerable<MyType> the underlying collection however is a RadObservableCollection<MyType> which in turn gets the data from the database through WCF RIA Services here's an extraction of the callback where the data is added to the collection:
myRadObservableCollection.SuspendNotifications();
myRadObservableCollection.Clear();
myRadObservableCollection.AddRange(o.Entities);
myRadObservableCollection.ResumeNotifications();
I'm not sure I will be able to test with latest internal build right now but I'll do my best. I'm currently using Q3 2010.
Tomas

I did a test with the latest internal build (2010.3.1304.1040). And the issue is still there. I've included a simple test application.
Run this code and try to change MyGroupProperty from 1 to 2 and you'll see the behvior.
xaml:
<
UserControl
x:Class
=
"SilverlightApplication2.MainPage"
xmlns:telerik
=
"http://schemas.telerik.com/2008/xaml/presentation"
mc:Ignorable
=
"d"
d:DesignHeight
=
"300"
d:DesignWidth
=
"400"
>
<
Grid
x:Name
=
"LayoutRoot"
Background
=
"White"
>
<
telerik:RadGridView
x:Name
=
"myGrid"
ItemsSource
=
"{Binding MyList}"
>
<
telerik:RadGridView.GroupDescriptors
>
<
telerik:GroupDescriptor
Member
=
"MyGroupProperty"
SortDirection
=
"Ascending"
>
<
telerik:GroupDescriptor.AggregateFunctions
>
<
telerik:CountFunction
Caption
=
"Entries count: "
/>
</
telerik:GroupDescriptor.AggregateFunctions
>
</
telerik:GroupDescriptor
>
</
telerik:RadGridView.GroupDescriptors
>
</
telerik:RadGridView
>
</
Grid
>
</
UserControl
>
cs:
using
System.Collections.Generic;
using
System.Windows.Controls;
using
Telerik.Windows.Data;
namespace
SilverlightApplication2
{
public
partial
class
MainPage : UserControl
{
public
MainPage()
{
InitializeComponent();
this
.DataContext =
this
;
}
private
RadObservableCollection<SimpleClass> myList;
public
IEnumerable<SimpleClass> MyList
{
get
{
if
(myList ==
null
)
{
myList =
new
RadObservableCollection<SimpleClass>()
{
new
SimpleClass() { MyIntProperty = 1, MyStringProperty =
"One"
, MyGroupProperty = 1},
new
SimpleClass() { MyIntProperty = 2, MyStringProperty =
"Two"
, MyGroupProperty = 1},
new
SimpleClass() { MyIntProperty = 3, MyStringProperty =
"Three"
, MyGroupProperty = 1},
new
SimpleClass() { MyIntProperty = 4, MyStringProperty =
"Four"
, MyGroupProperty = 2},
};
}
return
myList;
}
}
}
public
class
SimpleClass
{
public
int
MyIntProperty {
get
;
set
; }
public
string
MyStringProperty {
get
;
set
; }
public
int
MyGroupProperty {
get
;
set
; }
}
}
Tomas
The issue has been resolved and the fix will be available with our next Latest Internal Build as well as with the Service Pack release.
Thank you for your feedback.
Maya
the Telerik team

Hi Maya,
That sounds good! I have another question regarding this topic though.
As I wrote in the first post I've setup my GroupDescriptor like this:
<
telerik:RadGridView.GroupDescriptors
>
<
telerik:GroupDescriptor
Member
=
"OutputType"
SortDirection
=
"Ascending"
>
<
telerik:GroupDescriptor.AggregateFunctions
>
<
telerik:CountFunction
Caption
=
"Entries count: "
/>
</
telerik:GroupDescriptor.AggregateFunctions
>
</
telerik:GroupDescriptor
>
</
telerik:RadGridView.GroupDescriptors
>
Notice that I haven't specified the DisplayContent. In my model I've specified the OutputProperty like this:
[Display(Name =
"OutputType"
, ResourceType =
typeof
(ModelLocalization))]
public
int
OutputType {
get
;
set
; }
The RadGridview column it self picks this up and displays the correct localized value in the header. What I expected was since you tell the
GroupDescriptor to bind to the Output property that it would automatically pick up the localized value and display it in the Grouppanel as well.
But currently I have to explicitly set the DisplayContent property in the GroupDescriptor definition in xaml to bind to the same ResourceProperty as I have already done in my model, like this:
...
DisplayContent="{Binding Path=Model.OutputType, Source={StaticResource ResourceWrapper}}"
...
If I group at runtime the value shown in the grouppanel is the correct and localized one. Is this a bug too?
Tomas
The GroupDescriptor is not quite aware of its corresponding column. What you may try is to define a ColumnGroupDescriptor (in the code-behind) instead of the GroupDescriptor in xaml. You may take a look at our online documentation for a reference.
A ColumnGroupDescriptor may be defined as follows:
public MainPage()
{
InitializeComponent();
ColumnGroupDescriptor columnDescriptor = new ColumnGroupDescriptor();
columnDescriptor.Column = this.playersGrid.Columns[2];
this.playersGrid.GroupDescriptors.Add(columnDescriptor);
}
Regards,
Maya
the Telerik team

Yes your suggestions solves the value displayed on the screen but how do I add a Aggregatefunction to this group using this technique?
The online documentation (http://www.telerik.com/help/silverlight/gridview-grouping-aggregates.html) uses the old GroupDescriptor
Tomas
You may add the aggregate function directly to the corresponding to the ColumnGroupDescriptor column:
ColumnGroupDescriptor columnDescriptor = new ColumnGroupDescriptor();
columnDescriptor.Column = this.playersGrid.Columns[2];
CountFunction count = new CountFunction() { Caption = "Count: " };
columnDescriptor.Column.AggregateFunctions.Add(count);
this.playersGrid.GroupDescriptors.Add(columnDescriptor);
Regards,
Maya
the Telerik team

Hi Maya,
SP1 solved the increment/decrement issue, thank you.
I have one last (hopefully) question in this area.
In the AutoGeneratingColumn event of the RadGridView I check If a column is equal to OutputType and if so change
the default columntype to a combobox column as well as apply the grouping etc.
This works nicely however I noticed that the group by box in the grouppanel is left empty (see screenshot).
But if I add this line of code: comboBoxColumn.CopyPropertiesFrom(e.Column);
Everything works correct. Is this something I really have todo or is something going wrong inside the GridView?
Tomas
private
void
grid_AutoGeneratingColumn(
object
sender, Telerik.Windows.Controls.GridViewAutoGeneratingColumnEventArgs e)
{
if
(e.Column.UniqueName ==
"OutputType"
)
{
var comboBoxColumn =
new
GridViewComboBoxColumn()
{
ItemsSource = ViewModel.OutputTypes,
DataMemberBinding =
new
Binding(e.Column.UniqueName),
SelectedValueMemberPath =
"Key"
,
DisplayMemberPath =
"Value"
,
FilteringControl =
new
ComboBoxColumnFilteringControl()
};
comboBoxColumn.CopyPropertiesFrom(e.Column);
//this line solves the problem
e.Column = comboBoxColumn;
ColumnGroupDescriptor columnDescriptor =
new
ColumnGroupDescriptor() { Column = e.Column };
CountFunction count =
new
CountFunction() { Caption =
"Entries count cs: "
};
columnDescriptor.Column.AggregateFunctions.Add(count);
this
.grid.GroupDescriptors.Add(columnDescriptor);
}
}
Unfortunately, I was not able to reproduce the issue you reported. I am sending you the sample project I used for testing it. Please take a look at it and let me know in case I have missed something from your settings and requirements.
Furthermore, are you setting some theme to RadGridView ? Is this issue observed only for the GridViewComboBoxColumn or for the others too ? May you try to define the binding in your code-snippet as follows:
DataMemberBinding = new Binding((e.Column as GridViewDataColumn).DataMemberBinding.Path.Path),
Maya
the Telerik team

Hi Maya,
I found out where your test solution and my solution differs, I use a DataPager and it's the pager that's causing this behviour.
I have a DataPager declared like this:
<
telerik:RadDataPager
x:Name
=
"DataPager1"
Grid.Row
=
"1"
VerticalAlignment
=
"Top"
Source
=
"{Binding Clubs}"
DisplayMode
=
"All"
PageSize
=
"25"
IsTotalItemCountFixed
=
"True"
/>
<
telerik:RadGridView
Grid.Row
=
"0"
AutoGeneratingColumn
=
"clubsGrid_AutoGeneratingColumn"
Name
=
"clubsGrid"
ItemsSource
=
"{Binding Path=PagedSource, ElementName=DataPager1}"
AutoGenerateColumns
=
"True"
Margin
=
"5"
>
I also found a way no to use the CopyPropertiesFrom method and that is to switch order of the following lines:
e.Column = comboBoxColumn;
ColumnGroupDescriptor columnDescriptor = new ColumnGroupDescriptor() { Column = e.Column };
private void grid_AutoGeneratingColumn(object sender, Telerik.Windows.Controls.GridViewAutoGeneratingColumnEventArgs e)
{
if (e.Column.UniqueName == "OutputType")
{
var comboBoxColumn = new GridViewComboBoxColumn()
{
ItemsSource = ViewModel.OutputTypes,
DataMemberBinding = new Binding(e.Column.UniqueName),
SelectedValueMemberPath = "Key",
DisplayMemberPath = "Value",
FilteringControl = new ComboBoxColumnFilteringControl()
};
ColumnGroupDescriptor columnDescriptor = new ColumnGroupDescriptor() { Column = e.Column };
e.Column = comboBoxColumn; //setting this after columnDescriptor initialization also works
CountFunction count = new CountFunction() { Caption = "Entries count cs: " };
columnDescriptor.Column.AggregateFunctions.Add(count);
this.grid.GroupDescriptors.Add(columnDescriptor);
}
}
I'm not sure this is considered a bug or not but at least I found the cause of the problem, and also a quite simple solution.
Btw it happens with other columntypes as well and I'm using the Office_Silver theme but I don't think that's relevant.
Tomas
I am happy to see that you have found a solution for your scenario. Still, we will investigate the issue. However, I was not able to reproduce it even when using a RadDataPager. Did you manage to get the same behavior with the sample I previously attached ? Did you change the Theme ?
Maya
the Telerik team

You're absolutely right. At fist I was not able to reproduce it on the your sample project either so I started to investigate the differences and I just realized that for this error situation to occure one additional stetp is required. You need to wrap the grid and the pager inside a RadTabControl.
So by using your sample project as a base the only thing thats needs to be changed besides adding references to the newly included components is to use the following xaml instead:
<
UserControl
x:Class
=
"GridViewComboBoxColumn.MainPage"
xmlns:telerik
=
"http://schemas.telerik.com/2008/xaml/presentation"
xmlns:my
=
"clr-namespace:GridViewComboBoxColumn"
mc:Ignorable
=
"d"
d:DesignHeight
=
"700"
d:DesignWidth
=
"700"
>
<
UserControl.Resources
>
<
my:MyViewModel
x:Key
=
"MyViewModel"
/>
</
UserControl.Resources
>
<
telerik:RadTabControl
>
<
telerik:RadTabItem
Header
=
"Testing"
>
<
Grid
x:Name
=
"LayoutRoot"
Background
=
"White"
>
<
Grid.RowDefinitions
>
<
RowDefinition
Height
=
"*"
/>
<
RowDefinition
Height
=
"Auto"
/>
</
Grid.RowDefinitions
>
<
telerik:RadGridView
Grid.Row
=
"0"
AutoGeneratingColumn
=
"clubsGrid_AutoGeneratingColumn"
Name
=
"clubsGrid"
ItemsSource
=
"{Binding Path=PagedSource, ElementName=DataPager1}"
AutoGenerateColumns
=
"True"
Margin
=
"5"
>
</
telerik:RadGridView
>
<
telerik:RadDataPager
x:Name
=
"DataPager1"
Grid.Row
=
"1"
VerticalAlignment
=
"Top"
Source
=
"{Binding Clubs}"
DisplayMode
=
"All"
PageSize
=
"25"
IsTotalItemCountFixed
=
"True"
/>
</
Grid
>
</
telerik:RadTabItem
>
</
telerik:RadTabControl
>
</
UserControl
>
Tomas
Indeed, you quite correct. I have managed to reproduce the issue once the RadGridView is defined within a RadTabControl. Generally, the reason for the behavior you experience is that the Tab-control handles the events and creates its elements in its own sequence. Thus some of the events of the grid that relies on particular items to be created beforehand may not execute as expected. As the GridViewComboBoxColumn executes a separates logic for getting its required information, the data for the ColumnGroupDescriptor is not delivered on time.
However, we will still make a further investigation on the issue and try to resolve it.
Thank you for your patience and valuable feedback.
Maya
the Telerik team

How can make better this code? The idea is add CountFunction 'Days' in the groupHeader of 'Year' using ColumnGroupDescriptor in XAML.
This code repite the 'year' grouping and don't show the footer CountFunction.
<
telerik:RadGridView.GroupDescriptors
>
<
telerik:GroupDescriptor
Member
=
"Year"
SortDirection
=
"Descending"
>
<
telerik:GroupDescriptor.AggregateFunctions
>
<
telerik:CountFunction
Caption
=
"Days: "
/>
</
telerik:GroupDescriptor.AggregateFunctions
>
</
telerik:GroupDescriptor
>
<
telerik:ColumnGroupDescriptor
Column
=
"{Binding Columns[\Year\], ElementName=DateListBox}"
SortDirection
=
"Descending"
DisplayContent
=
"Year"
>
</
telerik:ColumnGroupDescriptor
>
<
telerik:ColumnGroupDescriptor
Column
=
"{Binding Columns[\Month\], ElementName=DateListBox}"
SortDirection
=
"Descending"
DisplayContent
=
"Month"
/>
<
telerik:ColumnGroupDescriptor
Column
=
"{Binding Columns[\DayOfWeek\], ElementName=DateListBox}"
SortDirection
=
"Descending"
DisplayContent
=
"DayOfWeek"
/>
</
telerik:RadGridView.GroupDescriptors
>
Tnks!.