Group by date.month

2 posts, 0 answers
  1. Mohamed Nazmi
    Mohamed Nazmi avatar
    2 posts
    Member since:
    Oct 2009

    Posted 08 Oct 2009 Link to this post

    Greetings
    I have an application that i am migrating to use rad winform controls
    One of my gridviews has a date column, the whole table holds 1 record per day
    I want to group by this column but by months not days

    I am using SQL server 2008 as DB holder and LTS as data layer
    note that i can't use Linq to do that grouping as it will make the table uneditable
  2. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 14 Oct 2009 Link to this post

    Hi Mohamed Nazmi,

    You can use CustomDataOperation for this behavior. Please view CustomDataOperation in our example application. You must make CustomGrouping and handle CustomGrouping event of RadGridView.

    void gridView_CustomGrouping(object sender, GridViewCustomGroupingEventArgs e)
    {
        DateTime date1 = e.CellValue1 as DateTime;
        DateTime date2 = e.CellValue2 as DateTime;
     
        if (date1 != null && date2 != null)
        {
            if (date1.Year == date2.Year && date1.Month == date2.Month)
            {
                e.SortResult = 0;
                return;
            }
     
            e.SortResult = date2.CompareTo(date2);
        }

    Best wishes,
    Julian Benkov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top