locked
My List view is ordering the items incorrectly

    Question

  • My List view for my windows phone app is showing things incorrectly.

    I need to sort the items chronologically(Thurs. Fri. Sat)

    however, once I formatted the key so that it was in Day Name, month, date, it orders it by alphabetical now instead of date.

     this.activitiesList.Add(new ScheduleItem(DateTime.Now, "Activity 1", "blahblah"));
                this.activitiesList.Add(new ScheduleItem(DateTime.Now, "Activity 2", "blahblah"));
                this.activitiesList.Add(new ScheduleItem(DateTime.Now, "Activity 3", "blahblah"));
                this.activitiesList.Add(new ScheduleItem(DateTime.Now, "Activity 4", "blahblah"));
                this.activitiesList.Add(new ScheduleItem(DateTime.Now, "Activity 5", "blahblah"));
    
                this.activitiesList.Add(new ScheduleItem(DateTime.Now.AddDays(1), "Activity 6", "blahblah"));
                this.activitiesList.Add(new ScheduleItem(DateTime.Now.AddDays(1), "Activity 7", "blahblah"));
                this.activitiesList.Add(new ScheduleItem(DateTime.Now.AddDays(1), "Activity 8", "blahblah"));
                this.activitiesList.Add(new ScheduleItem(DateTime.Now.AddDays(1), "Activity 9", "blahblah"));
    
                this.activitiesList.Add(new ScheduleItem(DateTime.Now.AddDays(2), "Activity 10", "blahblah"));
                this.activitiesList.Add(new ScheduleItem(DateTime.Now.AddDays(2), "Activity 11", "blahblah"));
                this.activitiesList.Add(new ScheduleItem(DateTime.Now.AddDays(2), "Activity 12", "blahblah"));
                this.activitiesList.Add(new ScheduleItem(DateTime.Now.AddDays(2), "Activity 13", "blahblah"));
    
                var sortResult = from act in activitiesList group act by act.Day.DayOfWeek + ", " + StaticIdentifiers.months[act.Day.Month - 1] + " " + StaticIdentifiers.ReturnOrdinal(act.Day.Day) into grp orderby grp.Key select grp;
                cvsActivities.Source = sortResult;

    This is the code I am using. It draws from the list view sample on Microsofts site.

    Thursday, July 24, 2014 5:58 AM

Answers

  • I fixed it by putting the Friday after the date. Its not exactly desirable, but it seems to be the only solution for not sorting alphabetical
    Friday, July 25, 2014 12:36 AM

All replies

  • I don't see anywhere in your code where you are sorting by date. You are grouping by DayOfWeek but not orderby act.<date field you want to sort on>

    Thursday, July 24, 2014 8:38 PM
    Owner
  • This was the only way I could get it to display the proper format. otherwise it shows

    "7/24/2014", which I don't want because that will be confusing to the users.

    since whatever I'm grouping by becomes the key.


    Thursday, July 24, 2014 8:40 PM
  • I fixed it by putting the Friday after the date. Its not exactly desirable, but it seems to be the only solution for not sorting alphabetical
    Friday, July 25, 2014 12:36 AM