This is a migrated thread and some comments may be shown as answers.

Show Date/Time in column, but Group By Date

4 Answers 116 Views
GridView
This is a migrated thread and some comments may be shown as answers.
James Craig
Top achievements
Rank 1
James Craig asked on 16 Jul 2010, 01:04 PM
Good Day All!

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

Sort by
0
Vlad
Telerik team
answered on 16 Jul 2010, 01:12 PM
Hello James,

 You can set this column DataMemberBinding to YourDateTimeProperty.Date. Here is an example:

... DataMemberBinding="{Binding OrderDate.Date}" ...

Regards,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Vlad
Telerik team
answered on 16 Jul 2010, 01:15 PM
Hello James,

 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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
James Craig
Top achievements
Rank 1
answered on 16 Jul 2010, 05:33 PM

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

0
James Craig
Top achievements
Rank 1
answered on 16 Jul 2010, 05:47 PM
Hello Vlad,

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
Tags
GridView
Asked by
James Craig
Top achievements
Rank 1
Answers by
Vlad
Telerik team
James Craig
Top achievements
Rank 1
Share this question
or