Skip to main content
A newer version of this page is available. .

How to: Implement Custom Sorting

  • 3 minutes to read

This example demonstrates how to implement custom sorting in the Grid Control. To do this, handle the GridControl.CustomColumnSort event, assign your custom sorted list to the e.Result property and set the e.Handled property to True.

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CustomSorting {
    public class SchedulerData {
        const int daysInWeek = 7;
        string[] employees = new string[] { "Jane", "Martin", "John", "Jack", "Amanda", "Carmen", "Wins", "Todd", "Ashley" };
        Random rnd = new Random();
        public List<SchedulerItem> Items { get; set; }
        public SchedulerData() {
            Items = new List<SchedulerItem>();
            GenerateRandomData();
        }
        void GenerateRandomData() {
            for (int i = 0; i < daysInWeek; i++) {
                int e1 = rnd.Next(employees.Length - 1);
                int e2 = e1 + 1;
                string day = DateTime.Today.AddDays(i).DayOfWeek.ToString();
                Items.Add(new SchedulerItem() { Day = day, Employee = employees[e1] });
                Items.Add(new SchedulerItem() { Day = day, Employee = employees[e2] });
            }
        }
    }

    public class SchedulerItem {
        public string Day { get; set; }
        public string Employee { get; set; }
    }
}