none
Sorting items by date and time, but have custom group titles. RRS feed

  • Question

  • I would like to sort my list by the date and time(So it can be in chronological order), however, I want to show the grouping as Day Month, year (Saturday November 4th, 2014). 

    How can I do this in C#.

    right now I'm using 

    var sortResult = from act in activitiesList group act by act.Day into grp orderby grp.Key select grp;
    cvsActivities.Source = sortResult;

    however, this makes the list sort every item into its own category

    • Moved by Jamles Hez Thursday, August 21, 2014 11:49 AM
    Wednesday, August 13, 2014 1:48 AM

Answers

  • Does this help?

    group act by act.Day.Date into grp

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Thursday, August 14, 2014 12:35 PM
    Moderator

All replies

  • You are grouping by the day, and every day is different, so you'll want to remove the time portion of the date and then try again.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Thursday, August 14, 2014 12:04 AM
    Moderator
  • Then the sub items aren't sorted by time. The group header needs to sort by day, and the items in the groups need to be in order by time. If i sort by day, then the sub items are out of order, as they are presented in the order that the server gives the data, which I am not in control of.
    Thursday, August 14, 2014 1:51 AM
  • Does this help?

    group act by act.Day.Date into grp

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Thursday, August 14, 2014 12:35 PM
    Moderator
  • Since parse.com is presenting the items in any order, the date sorting works fine, but each group is out of order with respect to time

    so i get

    11/14/2014

    Item 12:00PM

    Item 2 4:00PM

    Item 3 3:00PM

    11/15/2014

    Item 12:06PM

    Item 2 8:00 pm

    Item 3 5:00 pm

    Thursday, August 14, 2014 7:38 PM
  • One thought I had, is it possible to take a 

    List<CustomClass> and sort them by a property using LINQ?

    That way I can sort the items in order by the Hour they occur at, then take that list and group the events by day.


    Friday, August 15, 2014 8:45 PM