Good Day!
I wish to bind a Nullable<DateTime> property to a grid column; further, I wish to display and sort by date/time, but group by date alone & also have discrete date values only appear in the filter dialog. I'm using the following test code:
XAML:
<DataTemplate x:Key="ctd1">
<TextBlock Text="{Binding d1, Converter={StaticResource bConvDateTimeToCultureString}}" />
</DataTemplate>
...
<telerik:RadGridView Name="radGridView1">
<telerik:RadGridView.Columns>
<!--<telerik:GridViewDataColumn DataMemberBinding="{Binding Path=d1.Value.Date}" CellTemplate="{StaticResource ctd1}" /> -->
<telerik:GridViewDataColumn DataMemberBinding="{Binding Path=d1}" GroupMemberPath="d1.Value.Date" />
<telerik:GridViewDataColumn DataMemberBinding="{Binding Path=d2}" GroupMemberPath="d1.Value.Date" />
</telerik:RadGridView.Columns>
</telerik:RadGridView>
Code:
public class DatePair
{
public DateTime? d1 { get; set; }
public DateTime? d2 { get; set; }
public DatePair(int n)
{
d1 = DateTime.Now.AddDays(n);
d2 = DateTime.Now.AddMinutes(n + 10);
}
}
radGridView1.ItemsSource = new DatePair[] { new DatePair(12), new DatePair(13), new DatePair(14) };
Approach 1:
<telerik:GridViewDataColumn DataMemberBinding="{Binding Path=d1}" GroupMemberPath="d1.Value.Date" />
Problems:
Property group headers are formatted using the invariant culture
Filter dialog lists discrete values for each date/time. I want users to be able to select by discrete date (how can I control this?). Filter dialog also displays its dates according to the invariant culture (why this switch?).
Approach 2:
<telerik:GridViewDataColumn DataMemberBinding="{Binding Path=d1.Date}" CellTemplate="{StaticResource ctd1}" SortMemberPath="d1" />
Problems:
N.B. the CellTemplate's converter ensures that the date is formatted using the current culture (without this it's formatted using the invariant culture).
Can no longer perform grouping, grid runs poorly, but column is populated and sorts correctly.
Approach 3:
<telerik:GridViewDataColumn DataMemberBinding="{Binding Path=d1.Value.Date}" CellTemplate="{StaticResource ctd1}" SortMemberPath="d2" />
Problems:
Grouping is done by date, and group headers are formatted using the current culture (exactly what I want).
However, the filter dialog show dates in the invariant culture.
Binding errors like that below are raised every time rows are generated, causing an appreciable slowdown.
BindingExpression path error: 'Value' property not found on '05/08/2010 15:21:18' 'System.DateTime' (HashCode=-196747520). BindingExpression: Path='d1.Value.Date' DataItem='SilverlightTestApp.MainPage+DatePair' (HashCode=36615679); target element is 'Telerik.Windows.Controls.GridView.GridViewCell' (Name=''); target property is 'Value' (type 'System.Object').
Please can someone advise as to the correct way to handle this scenario?
Many thanks,
James