Krypton OutlookGrid

Group, sort and watch !

Custom open-source datagridview with multi-grouping and multi-sorting capabilities for C# Winforms.

Documentation

This section will guide you how to use the Krypton OutlookGrid.

Please read the original article from Herre Kuijpers to understand how the grid functions on the top of the Winforms (Krypton)DataGridView.


Installation

1. Installing Krypton Suite

Krypton Outlook relies on the Krypton Suite from Component Factory, which is now open-source under BSD license.

Some modifications were required to the source of the Krypton Toolkit on which the grid relies on. Thus, please refer to my fork of the Krypton Suite : https://github.com/Cocotteseb/Krypton. Follow the instructions to set up your dev environnement.

2. Add references

Add a reference to ComponentFactory.Krypton.Toolkit.dll and JDHSoftware.Krypton.Toolkit.KryptonOutlookGrid.dll to your project. You can either doing it by adding the projects to your solution or referencing directly the dlls.


How to use

1. Drag and drop the KryptonOutlookGrid and KryptonOutlookGridGroupBox on the Form.
2. Associate the KryptonOutlookGridGroupBox with the grid by design time or by code using the following :

OutlookGrid1.GroupBox = KryptonOutlookGridGroupBox1;

3. We need that the OutlookGrid listens to the GroupBox actions/events.

OutlookGrid1.RegisterGroupBoxEvents();

4. Design your grid by configuring your columns as you would do with the standard datagridview in unbound mode. You can do it by code or by design time.
Warning you must respect these two rules :

  • The column SortMode property must be set to "Programmatic" as the grid will handle itself the sorting.
  • The column Name property must not be empty (whereas the HeaderText could be).
DataGridViewColumn[] columnsToAdd = new DataGridViewColumn[10];
columnsToAdd[0] = SetupColumn(SandBoxGridColumn.ColumnCustomerID);
columnsToAdd[1] = SetupColumn(SandBoxGridColumn.ColumnCustomerName);
columnsToAdd[2] = SetupColumn(SandBoxGridColumn.ColumnAddress);
...
Grid.Columns.AddRange(columnsToAdd);

5. Configure the OutlookGrid. For grouping and sorting abilities we need to precise the columns to the grid.

Grid.AddInternalColumn(columnsToAdd[0], new OutlookGridDefaultGroup(null), SortOrder.None, -1, -1);
Grid.AddInternalColumn(columnsToAdd[1], new OutlookGridAlphabeticGroup(null), SortOrder.None, -1, -1);
Grid.AddInternalColumn(columnsToAdd[2], new OutlookGridDefaultGroup(null), SortOrder.None, -1, -1);
...
The different parameters for the AddInternalColumn procedure are:
  • Parameter 1 : the datagridview column
  • Parameter 2 : the IOutlookGridGroup that will be used when the column will be grouped
  • Parameter 3 : the sort direction
  • Parameter 4 : the column position among grouped columns, -1 if not grouped.
  • Parameter 5 : the column position among sorted columns, -1 if not sorted.

Please note that a grouped column will automatically be sorted.

You can customize the default group with some properties :

  • Single (OneItemText) and multiple items (XXXItemsText) : this allows you to change the word "item" by the current object you are displaying in the grid and manage the specificities of each country regarding the plural.
  • SortBySummaryCount : This indicates if the groups should be sorted by the number of elements in each group rather the group element value
  • ItemsComparer : for complex objects you can set your own comparer. It will be used during sort operations.
  • Interval : only for the OutlookGridDateTimeGroup, you can specify type of grouping you want to use : day, month, quarter, year and intelligent (such as Outlook)

6. Fill the grid with data (unbound mode only).

//Setup Rows
OutlookGridRow row = new OutlookGridRow();
List l = new List();
OutlookGrid1.SuspendLayout();
OutlookGrid1.ClearInternalRows();
foreach (item in items)
{
     try
     {
           row = new OutlookGridRow();
           row.CreateCells(OutlookGrid1, new object[] {
                    item.Prop1,
                    item.Prop2,
                   ....
      });
      l.Add(row);
}
OutlookGrid1.ResumeLayout();
OutlookGrid1.AssignRows(l);
OutlookGrid1.ForceRefreshGroupBox();
OutlookGrid1.Fill();

7. Enjoy !

Going further

The KryptonOutlookGrid.Sandbox that is shipped with the source is a complete example in C# on how to use the grid. Let's see some more advanced usage :