Hello,
I encountered a problem with the GridView WPF-Control. When I use a Converter in the DataMemberBinding of a column and group by that column, the result will be grouped by the unconverted value.
To show the problem, i set up a small test project with a small "Person" class with "Name" (string), "Age" (int) and "Status" (int) properties.
In the test project, three persons-objects will be created and bound to a GridView. Each property in a seperate column.
The "Status" column uses a converter for the DataMemberBinding:
The Status of the three persons are 122, 123, 321, and they appear correctly converted in the list.
Obviously the result, after a group by Status, should show the persons with Status 123 and 123 in one group because their Status is below 256.
But it seems the converter won't be used for grouping and every person appear in a single group.
Is there a solution for this problem ?
Thanks, Michael
I encountered a problem with the GridView WPF-Control. When I use a Converter in the DataMemberBinding of a column and group by that column, the result will be grouped by the unconverted value.
To show the problem, i set up a small test project with a small "Person" class with "Name" (string), "Age" (int) and "Status" (int) properties.
In the test project, three persons-objects will be created and bound to a GridView. Each property in a seperate column.
The "Status" column uses a converter for the DataMemberBinding:
<Window x:Class="RadGridViewColumnTest.Window1" |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" |
xmlns:System="clr-namespace:System;assembly=mscorlib" |
xmlns:local="clr-namespace:RadGridViewColumnTest" |
Title="Window1" Height="300" Width="300"> |
<Grid> |
<Grid.Resources> |
<local:StatusConverter x:Key="StatusConverterResource"> |
</local:StatusConverter> |
</Grid.Resources> |
<telerik:RadGridView x:Name="grid" AutoGenerateColumns="False" Grouping="grid_Grouping"> |
<telerik:RadGridView.Columns> |
<telerik:GridViewDataColumn HeaderText="Person" DataMemberBinding="{Binding .Name}" DataType="{x:Type System:String}"> |
</telerik:GridViewDataColumn> |
<telerik:GridViewDataColumn HeaderText="Age" DataMemberBinding="{Binding .Age}" DataType="{x:Type System:Int32}"/> |
<telerik:GridViewDataColumn HeaderText="Status" DataMemberBinding="{Binding Path=Status, Converter={StaticResource StatusConverterResource}}" IsSortable="True" DataType="{x:Type System:Int32}" IsGroupable="True"/> |
</telerik:RadGridView.Columns> |
</telerik:RadGridView> |
</Grid> |
</Window> |
public class StatusConverter : IValueConverter |
{ |
#region IValueConverter Members |
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) |
{ |
if ((int)value < 256) |
{ |
return "< 256"; |
} |
else |
return ">= 256"; |
} |
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) |
{ |
throw new NotImplementedException(); |
} |
#endregion |
} |
The Status of the three persons are 122, 123, 321, and they appear correctly converted in the list.
Obviously the result, after a group by Status, should show the persons with Status 123 and 123 in one group because their Status is below 256.
But it seems the converter won't be used for grouping and every person appear in a single group.
Is there a solution for this problem ?
Thanks, Michael