Hi
I want to fetch the SalePrice in the label below, it does not work. The below code is what I got so far.
After searching for a few hours I give up. I hope you can help.
<
telerik:GridViewDataColumn
UniqueName
=
"Title"
IsReadOnly
=
"True"
IsVisible
=
"True"
x:Name
=
"showTitleColumn"
DataMemberBinding
=
"{Binding Path=OrderDetailGroupingTitle}"
Header
=
"Titel"
Width
=
"auto"
>
<
telerik:GridViewDataColumn.GroupHeaderTemplate
>
<
DataTemplate
>
<
StackPanel
Orientation
=
"Horizontal"
>
<
telerik:Label
Content
=
"Test"
/>
<
telerik:Label
Foreground
=
"{StaticResource StrongBrush}"
Content
=
"{Binding Group.Items[0].SalePrice}"
/>
<
telerik:Label
Foreground
=
"{StaticResource StrongBrush}"
FontWeight
=
"Bold"
Content
=
"{Binding Group.Key}"
/>
</
StackPanel
>
</
DataTemplate
>
</
telerik:GridViewDataColumn.GroupHeaderTemplate
>
</
telerik:GridViewDataColumn
>
12 Answers, 1 is accepted
The DataContext of the group row (and the StackPanel consequently) is GroupViewModel. As you could check in the link, it contains properties like Group, Column, AggregateResults etc. Each Group in the GroupViewModel has an Items collection. Would you please check if the Items[0] object is present and has a property SalePrice?
Didie
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

I don't know how to to check how Items[0] object is present and has a property SalePrice. I cannot break an inspect in the xaml there.
I understand that the datacontext is not the same one as the grid itself. Maybe I should go that route and set the context to the one of the grid and bind normally? I searched for examples but they did not work either.
Do you have a sample where you group in a column template and bind one of the regular controls to a grid collection item ?
Thanks anyway
I have attached a sample project showing how you could bind to the property of the Items[0] item. As I previously said the DataContext of the group row is a GroupViewModel. Do you need it to be something else?
All the best,Didie
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Thanks for the example. It is almost what I want.
This example works with only one level of grouping but does not work for two. Let me show you:
<
telerik:RadGridView
Grid.Row
=
"0"
Name
=
"clubsGrid"
ItemsSource
=
"{Binding Clubs}"
AutoGenerateColumns
=
"False"
>
<
telerik:RadGridView.GroupDescriptors
>
<
telerik:GroupDescriptor
Member
=
"Name"
/>
</
telerik:RadGridView.GroupDescriptors
>
<
telerik:RadGridView.Columns
>
<
telerik:GridViewDataColumn
DataMemberBinding
=
"{Binding Name}"
>
<
telerik:GridViewDataColumn.GroupHeaderTemplate
>
<
DataTemplate
>
<
StackPanel
>
<
TextBlock
Foreground
=
"#FFED1691"
Text
=
"{Binding Group.Items[0].StadiumCapacity}"
/>
<
TextBlock
Foreground
=
"#FFED7971"
Text
=
"{Binding Group.Key}"
/>
</
StackPanel
>
</
DataTemplate
>
</
telerik:GridViewDataColumn.GroupHeaderTemplate
>
</
telerik:GridViewDataColumn
>
<
telerik:GridViewDataColumn
DataMemberBinding
=
"{Binding Established}"
DataFormatString
=
"yyyy"
Header
=
"Est."
/>
</
telerik:RadGridView.Columns
>
</
telerik:RadGridView
>
<
telerik:RadGridView
Grid.Row
=
"0"
Name
=
"clubsGrid"
ItemsSource
=
"{Binding Clubs}"
AutoGenerateColumns
=
"False"
>
<
telerik:RadGridView.GroupDescriptors
>
<
telerik:GroupDescriptor
Member
=
"Name"
/>
<
telerik:GroupDescriptor
Member
=
"Established"
/>
</
telerik:RadGridView.GroupDescriptors
>
<
telerik:RadGridView.Columns
>
<
telerik:GridViewDataColumn
DataMemberBinding
=
"{Binding Name}"
>
<
telerik:GridViewDataColumn.GroupHeaderTemplate
>
<
DataTemplate
>
<
StackPanel
>
<
TextBlock
Foreground
=
"#FFED1691"
Text
=
"{Binding Group.Items[0].StadiumCapacity}"
/>
<
TextBlock
Foreground
=
"#FFED7971"
Text
=
"{Binding Group.Key}"
/>
</
StackPanel
>
</
DataTemplate
>
</
telerik:GridViewDataColumn.GroupHeaderTemplate
>
</
telerik:GridViewDataColumn
>
<
telerik:GridViewDataColumn
DataMemberBinding
=
"{Binding Established}"
DataFormatString
=
"yyyy"
Header
=
"Est."
/>
</
telerik:RadGridView.Columns
>
</
telerik:RadGridView
>
if you would copy and paste this code in the project the wysiwyg VS editor will show the difference.
I hope you can help!
Thanks,
Edward
Indeed, you are right. Please predefine the HeaderTemplate for the column bound to the "Established" property and let me know if now the text in the GroupHeaderTemplate is the one you expect?
Regards,Didie
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

<
telerik:RadGridView
Grid.Row
=
"0"
Name
=
"clubsGrid"
ItemsSource
=
"{Binding Clubs}"
AutoGenerateColumns
=
"False"
>
<
telerik:RadGridView.GroupDescriptors
>
<
telerik:GroupDescriptor
Member
=
"Name"
/>
<
telerik:GroupDescriptor
Member
=
"Established"
/>
</
telerik:RadGridView.GroupDescriptors
>
<
telerik:RadGridView.Columns
>
<
telerik:GridViewDataColumn
DataMemberBinding
=
"{Binding Name}"
>
<
telerik:GridViewDataColumn.GroupHeaderTemplate
>
<
DataTemplate
>
<
StackPanel
>
<
TextBlock
Foreground
=
"#FFED1691"
Text
=
"{Binding GroupDescriptor.Established}"
/>
<
TextBlock
Foreground
=
"#FFED7971"
Text
=
"{Binding Group.Key}"
/>
</
StackPanel
>
</
DataTemplate
>
</
telerik:GridViewDataColumn.GroupHeaderTemplate
>
</
telerik:GridViewDataColumn
>
<
telerik:GridViewDataColumn
DataMemberBinding
=
"{Binding Established}"
DataFormatString
=
"yyyy"
Header
=
"Est."
/>
</
telerik:RadGridView.Columns
>
</
telerik:RadGridView
>
The values does not shown as this Binding is not correct.
<
TextBlock
Foreground
=
"#FFED1691"
Text
=
"{Binding GroupDescriptor.Established}"
/>
Please note that the DataContext of the group row (and the StackPanel consequently) is GroupViewModel. As you can check in the link, it contains properties like Group, Column, AggregateResults, Items etc. Each Group in the GroupViewModel has an Items collection. Would you please check if the Items[0] object is present for the specific group rows and has the property which value you would like to show?
Greetings,Didie
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

I ment:
<
TextBlock
Foreground
=
"#FFED1691"
Text
=
"{Binding Group.Items[0].Established}"
/>
Still nada.
It looks like the Items[0] object is present (not sure how to check this) but not the property. How do I get access to that Established property ?
Greetings,
Edward
When you have more than 1 grouping, then the most inner Group Row will have Items of type the bound business object. That is why it shows the value of the Established property. When we talk about the outer Group Rows, then their Items are the inner Group Rows and they do not have an Established property.
Please find my test project attached for you reference.
Kind regards,
Didie
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

So how can I access another data item of the business object in the outer Group rows? Via InnerGroup ?
The result should look Like:
Liverpool 1892
-- whatever
Manchester United 1878
-- whatever
...
..
.
Greeting,
Edward
In that case you will have to define the HeaderTemplate for the "Name" column like so:
<
telerik:GridViewDataColumn.GroupHeaderTemplate
>
<
DataTemplate
>
<
StackPanel
>
<
TextBlock
Foreground
=
"Green"
Text
=
"Test Items[0].Established"
/>
<
TextBlock
Foreground
=
"Green"
Text
=
"{Binding Group.Items[0].Items[0].Established}"
/>
<
TextBlock
Foreground
=
"#FFED7971"
Text
=
"Test Key"
/>
<
TextBlock
Foreground
=
"#FFED7971"
Text
=
"{Binding Group.Key}"
/>
</
StackPanel
>
</
DataTemplate
>
</
telerik:GridViewDataColumn.GroupHeaderTemplate
>
Please note that you this will work when you have grouping on two columns (Name and Established in your case).
Kind regards, Didie
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Thanks!