1. Complex data types
When the value to group by is a simple datatype, say a string, the default headers work fine. But when grouping by a columns that is bound to a complex datatype it doesn't look as good. In those cases the headers will show all the properties of the class and the values in it.
An example:
Let's say I have a class:
public
class
MemberType
{
public
int
Id {
get
;
set
; }
public
string
Description {
get
;
set
; }
}
"Id:1 Desciption:Editor" and so on. How can I specify that I only want to show the value of the Description i the group headers (which is what the rows are grouped by).
2. Boolean values
When the value to group by is a boolean, there will be two groups with the headers "true" and "false" (assuming both values are represented in the data). This is the desired behavior, but I would like the headers to be "Yes" and "No" instead.
6 Answers, 1 is accepted
However, it would be nice if there was another way. The ToString() method might already be used for other purposes...
You can achieve the same result using the GroupHeaderTemplate property of GridViewColumn.
Best wishes,Yavor Georgiev
the Telerik team
I found this example:
<
telerik:GridViewDataColumn.GroupHeaderTemplate
>
<
DataTemplate
>
<
TextBlock
Foreground
=
"Green"
Text
=
"{Binding Group.Key}"
/>
</
DataTemplate
>
</
telerik:GridViewDataColumn.GroupHeaderTemplate
>
I don't understand how I can use this to fix my scenarios. Could you give me an example?
The Group.Key property contains your business object. Thus you can bind to its various properties such as Group.Key.MyProperty or Group.Key.MyOtherProperty.
All the best,Yavor Georgiev
the Telerik team
I handled the general need to display a custom group header like this. - the case is what is displayed when the group is collapsed in a RadGridView and solving the problem with the GroupHeaderTemplate.
The xaml is like this
<
te:RadGridView.GroupHeaderTemplate
><
br
> <
DataTemplate
><
br
>
<!-- I couldnt find a Path binding that wouldnt break the converter,<br> so I grab the default stuff the framework sends it. -->
<
br
> <
TextBlock
Text
=
"{Binding Converter={StaticResource PropertyNameConverter}}"
/><
br
> </
DataTemplate
><
br
></
te:RadGridView.GroupHeaderTemplate
>
In the UserControl.Resources I need to put a key on my value converter
<
UserControl.Resources
><
br
> <
cons:PropertyNameConverter
x:Key
=
"PropertyNameConverter"
></
cons:PropertyNameConverter
><
br
> </
UserControl.Resources
>
and in the xmlns declarations a reference to the file the value converter is in
xmlns:cons="clr-namespace:SmartObjMgr.Helpers"
and the value converter looks like this. I couldn't get Group.Key or Path to send a value to the value converter, but I found that the data value I needed was passed in the value parameter automatically.
public
class
PropertyNameConverter : IValueConverter<br>{<br>
public
object
Convert(
object
value, Type targetType,
object
parameter, CultureInfo culture)<br> {<br> var IoValue = ((GroupViewModel)value).Header;<br>
string
TheLabel =
""
;<br>
switch
(IoValue)<br> {<br>
case
"Input"
:<br> TheLabel =
"Input Property"
;<br>
break
;<br>
case
"Return"
:<br> TheLabel =
"Return Property"
;<br>
break
;<br>
case
"Parameter"
:<br> TheLabel =
"Parameter Property"
;<br>
break
;<br>
default
:<br> TheLabel =
"Property"
;<br>
break
;<br> }<br>
if
(TheLabel ==
"Property"
) { MessageBox.Show(IoValue +
" needs to be handled in Helper, PropertyNameConverter."
,
"Edit App Code"
); }<br>
return
TheLabel;<br> }
It works.
I'm glad to hear that you've found a suitable solution. If you require any further assistance, please let us know.
Regards,
Dilyan Traykov
Progress Telerik