
I'm building my grid's structure by adding columns (unknown until runtime) dynamically. Any DateTime? column I add must display the full date and time (so I can't bind to the DateTime's Date property), however it must group by date alone (disregarding the time component).
Please could someone let me know if this can be done and how? It's a quite urgent requirement, alas :(
Many thanks,
James
4 Answers, 1 is accepted
You can set this column DataMemberBinding to YourDateTimeProperty.Date. Here is an example:
... DataMemberBinding="{Binding OrderDate.Date}" ...
Vlad
the Telerik team
Sorry - I'm too fast! You can set CellTemplate with a regular TextBlock to show the full DateTime and keep the binding to DateTime.Date.
Best wishes,Vlad
the Telerik team

Hello Vlad,
Many thanks indeed for your rapid response! Unfortunately, I'm having a little difficulty with this, as I need to bind to a property of type Nullable<DateTime>, rather than DateTime. If I bind to the property path 'myNullableDtProp.Date', the column's cells are populated with values but 1) grid performance appears to degrade significantly, and 2) I lose sorting/filtering/grouping'. If I bind to the property path 'myNullableDtProp.Value.Date', sorting and grouping work fine, but the column's cells are all blank!
The following code demonstrates this:
GridViewDataColumn gvCol = new GridViewDataColumn();
Binding binding = new Binding("d1.Date");
gvCol.DataMemberBinding = binding;
radGridView1.Columns.Add(gvCol);
gvCol = new GridViewDataColumn();
binding = new Binding("d2.Date");
gvCol.DataMemberBinding = binding;
radGridView1.Columns.Add(gvCol);
radGridView1.ItemsSource = new DatePair[] { new DatePair(12), new DatePair(13), new DatePair(14) };
public class DatePair
{
public DateTime? d1 { get; set; }
public DateTime? d2 { get; set; }
public DatePair(int n)
{
d1 = DateTime.Now.AddYears(n);
d2 = null;//DateTime.Now.AddYears(n + 1);
}
}
Could you please suggest a workaround?
Best regards,
James

Apologies - this time it was I who jumped the gun :)
Using the '.Value.Date' binding in conjunction with a CellTemplate works perfectly
Many thanks for your help. The helpfulness of Telerik staff continues to impress!
Best regards,
James