# grid-interval-grouping

> Grid that groups rows by ShippedDate month and Order ID, applying a custom KeySelector and a SortComparer per column to an Orders data source.

**Framework:** winforms  **Component:** Grid  **Variant:** interval-grouping

## Get this item

**If you are an agent, fetch the JSON.** Source is inlined, so one request is enough and no tooling is required:

```
GET https://ai.syncfusion.com/r/winforms/grid-interval-grouping.json
```

**Install Package(s)**

```bash
dotnet add package Syncfusion.SfDataGrid.WinForms
```

**Notes**

- Syncfusion release: 2026 Volume 3 (v35.1.37)
- The Syncfusion package is licensed. The composition in this file is source you own and edit. See https://ai.syncfusion.com/licensing.md

## Source files

### src/components/grid-interval-grouping/grid.Designer.cs

```cs
using Syncfusion.Windows.Forms;
using Syncfusion.WinForms.DataGrid;
using Syncfusion.WinForms.DataGrid.Enums;
using System.Windows.Forms;

namespace IntervalGrouping
{
    partial class Form1
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.sfDataGrid1 = new Syncfusion.WinForms.DataGrid.SfDataGrid();
            this.label3 = new System.Windows.Forms.Label();
            this.label4 = new System.Windows.Forms.Label();
            this.label5 = new System.Windows.Forms.Label();
            this.label6 = new System.Windows.Forms.Label();
            this.label7 = new System.Windows.Forms.Label();
            this.label8 = new System.Windows.Forms.Label();
            this.label9 = new System.Windows.Forms.Label();
            this.label10 = new System.Windows.Forms.Label();
            ((System.ComponentModel.ISupportInitialize)(this.sfDataGrid1)).BeginInit();
            this.SuspendLayout();
            //
            // sfDataGrid1
            //
            this.sfDataGrid1.AccessibleName = "Table";
            this.sfDataGrid1.AllowEditing = false;
            this.sfDataGrid1.AllowFiltering = true;
            this.sfDataGrid1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
            | System.Windows.Forms.AnchorStyles.Left)
            | System.Windows.Forms.AnchorStyles.Right)));
            this.sfDataGrid1.AutoSizeColumnsMode = Syncfusion.WinForms.DataGrid.Enums.AutoSizeColumnsMode.Fill;
            this.sfDataGrid1.Location = new System.Drawing.Point(10, 5);
            this.sfDataGrid1.Margin = new System.Windows.Forms.Padding(5);
            this.sfDataGrid1.Name = "sfDataGrid1";
            this.sfDataGrid1.RowHeight = (int)DpiAware.LogicalToDeviceUnits(21.0f);
            this.sfDataGrid1.ShowGroupDropArea = true;
            this.sfDataGrid1.Size = new System.Drawing.Size(708, 540);
            this.sfDataGrid1.TabIndex = 1;
            this.sfDataGrid1.Text = "sfDataGrid1";
            //
            // label3
            //
            this.label3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
            this.label3.AutoSize = true;
            this.label3.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.label3.Location = new System.Drawing.Point(733, 39);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(153, 20);
            this.label3.TabIndex = 3;
            this.label3.Text = "Interval Grouping";
            //
            // label4
            //
            this.label4.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
            this.label4.AutoSize = true;
            this.label4.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.label4.Location = new System.Drawing.Point(733, 83);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(217, 20);
            this.label4.TabIndex = 4;
            this.label4.Text = "Order Id, Freight Column";
            //
            // label5
            //
            this.label5.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
            this.label5.AutoSize = true;
            this.label5.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.label5.Location = new System.Drawing.Point(731, 148);
            this.label5.Name = "label5";
            this.label5.Size = new System.Drawing.Size(303, 20);
            this.label5.TabIndex = 5;
            this.label5.Text = "Customer ID, Ship Country Column";
            //
            // label6
            //
            this.label6.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
            this.label6.AutoSize = true;
            this.label6.Location = new System.Drawing.Point(767, 108);
            this.label6.Name = "label6";
            this.label6.Size = new System.Drawing.Size(175, 17);
            this.label6.TabIndex = 6;
            this.label6.Text = "Groups based on Intervals";
            //
            // label7
            //
            this.label7.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
            this.label7.AutoSize = true;
            this.label7.Location = new System.Drawing.Point(767, 173);
            this.label7.Name = "label7";
            this.label7.Size = new System.Drawing.Size(205, 17);
            this.label7.TabIndex = 7;
            this.label7.Text = "Groups based on starting letter";
            //
            // label8
            //
            this.label8.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
            this.label8.AutoSize = true;
            this.label8.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.label8.Location = new System.Drawing.Point(731, 217);
            this.label8.Name = "label8";
            this.label8.Size = new System.Drawing.Size(296, 20);
            this.label8.TabIndex = 8;
            this.label8.Text = "Order Date, Shipped Date Column";
            //
            // label9
            //
            this.label9.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
            this.label9.AutoSize = true;
            this.label9.Location = new System.Drawing.Point(767, 258);
            this.label9.Name = "label9";
            this.label9.Size = new System.Drawing.Size(275, 17);
            this.label9.TabIndex = 9;
            this.label9.Text = "Order Date - Groups based on date range";
            //
            // label10
            //
            this.label10.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
            this.label10.AutoSize = true;
            this.label10.Location = new System.Drawing.Point(767, 289);
            this.label10.Name = "label10";
            this.label10.Size = new System.Drawing.Size(260, 17);
            this.label10.TabIndex = 10;
            this.label10.Text = "Shipped Date - Groups based on month";
            //
            // Form1
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.BackColor = System.Drawing.Color.White;
            this.Size = new System.Drawing.Size(1024, 640);
            this.Controls.Add(this.label10);
            this.Controls.Add(this.label9);
            this.Controls.Add(this.label8);
            this.Controls.Add(this.label7);
            this.Controls.Add(this.label6);
            this.Controls.Add(this.label5);
            this.Controls.Add(this.label4);
            this.Controls.Add(this.label3);
            this.Controls.Add(this.sfDataGrid1);
            this.Margin = new System.Windows.Forms.Padding(5);
            this.MinimumSize = new System.Drawing.Size(500, 400);
            this.Name = "Form1";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "Interval Grouping";
            ((System.ComponentModel.ISupportInitialize)(this.sfDataGrid1)).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        #region API Definition

        private SfDataGrid sfDataGrid1;
        private Label label3;
        private Label label4;
        private Label label5;
        private Label label6;
        private Label label7;
        private Label label8;
        private Label label9;
        private Label label10;

        #endregion

    }
}
```

### src/components/grid-interval-grouping/grid.cs

```cs
using Syncfusion.Data;
using Syncfusion.WinForms.DataGrid;
using System.Globalization;
using System.Windows.Forms;

namespace IntervalGrouping
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            OrderInfoCollection orderInfo = new OrderInfoCollection();
            sfDataGrid1.DataSourceChanged += SfDataGrid1_DataSourceChanged;
            sfDataGrid1.BeginUpdate();
            sfDataGrid1.DataSource = orderInfo.OrdersListDetails;
            this.sfDataGrid1.SortComparers.Add(new SortComparer()
            {
                PropertyName = "ShippedDate",
                Comparer = new GroupDateComparer(),
            });

            this.sfDataGrid1.SortComparers.Add(new SortComparer()
            {
                PropertyName = "OrderID",
                Comparer = new GroupNumericComparer(),
            });

            this.sfDataGrid1.GroupColumnDescriptions.Add(new GroupColumnDescription()
            {
                ColumnName = "ShippedDate",
                KeySelector = (string ColumnName, object o) =>
                {
                    var shipDate = (o as OrderInfo).ShippedDate;
                    return shipDate.ToString("MMMM yyyy");
                }
            });

            sfDataGrid1.EndUpdate();
        }

        private void SfDataGrid1_DataSourceChanged(object sender, Syncfusion.WinForms.DataGrid.Events.DataSourceChangedEventArgs e)
        {
            if (e.NewView != null)
                e.NewView.GroupDescriptions.CollectionChanged += GroupDescriptions_CollectionChanged;
            if (e.OldView != null)
                e.NewView.GroupDescriptions.CollectionChanged -= GroupDescriptions_CollectionChanged;
        }

        private void GroupDescriptions_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
            {
                if ((e.NewItems[0] as ColumnGroupDescription).PropertyName == "OrderID")
                {
                    (e.NewItems[0] as ColumnGroupDescription).KeySelector = (string OrderID, object o) =>
                    {
                        var orderID = (o as OrderInfo).OrderID;
                        var i = (int)orderID / 10;
                        int GroupingIntervalFrom = (int)i * 10;
                        int GroupingIntervalTo = ((int)i + 1) * 10;
                        return GroupingIntervalFrom.ToString(CultureInfo.InvariantCulture) + " to " + GroupingIntervalTo.ToString(CultureInfo.InvariantCulture);
                    };
                }

                if ((e.NewItems[0] as ColumnGroupDescription).PropertyName == "ShippedDate")
                {
                    (e.NewItems[0] as ColumnGroupDescription).KeySelector = (string ShippedDate, object o) =>
                    {
                        var shipDate = (o as OrderInfo).ShippedDate;
                        return shipDate.ToString("MMMM yyyy");
                    };
                }

                if ((e.NewItems[0] as ColumnGroupDescription).PropertyName == "CustomerID")
                {
                    (e.NewItems[0] as ColumnGroupDescription).KeySelector = (string CustomerID, object o) =>
                    {
                        var customerID = (o as OrderInfo).CustomerID;
                        return customerID[0];
                    };
                }

                if ((e.NewItems[0] as ColumnGroupDescription).PropertyName == "ShipCountry")
                {
                    (e.NewItems[0] as ColumnGroupDescription).KeySelector = (string ShipCountry, object o) =>
                    {
                        var shipCountry = (o as OrderInfo).ShipCountry;
                        return shipCountry[0];
                    };
                }
            }
        }
    }
}
```
