ComponentOne True DBGrid for .NET (2.0) Search HelpCentral 

Group Rows by Year

This topic demonstrates how to use the GroupIntervalEnum.Year member in C1TrueDBGrid.

1.   Start a new .NET project.

2.   Open the Toolbox and add a C1TrueDBGrid control to the form.

3.   Open the C1TrueDBGrid Tasks menu, click the drop-down arrow in the Choose Data Source box and click Add Project Data Source. In the Data Source Configuration Wizard, either select a connection to NWind.mdb or create a new connection to this database. On the Choose your database objects page of the wizard, select all fields in the Employees table and type "Employees" into the DataSet name box, and then finish out the wizard.

4.   Visual Studio adds the following code to the Form_Load event:

·      Visual Basic

Me.EmployeesTableAdapter.Fill(Me.Employees._Employees)

·      C#

this.EmployeesTableAdapter.Fill(this.Employees._Employees);

·      Delphi

Self.EmployeesTableAdapter.Fill(Self.Employees._Employees);

5.   Set the DataView property to DataViewEnum.GroupBy.

In the Designer

In the C1TrueDBGrid Tasks menu, select GroupBy from the Data Layout drop-down.

In Code

Add the following code to the Form_Load event:

·      Visual Basic

Me.C1TrueDBGrid1.DataView = C1.Win.C1TrueDBGrid.DataViewEnum.GroupBy

·      C#

this.c1TrueDBGrid1.DataView = C1.Win.C1TrueDBGrid.DataViewEnum.GroupBy;

·      Delphi

Self.C1TrueDBGrid1.DataView := C1.Win.C1TrueDBGrid.DataViewEnum.GroupBy;

6.   Open the C1TrueDBGrid Designer by selecting Designer from the C1TrueDBGrid Tasks menu.

7.   Select the HireDate column by clicking on it in the right pane.

The column can also be selected by choosing HireDate from the drop-down list in the toolbar.

8.   Set the Interval property to GroupIntervalEnum.Year.

In the Designer

Locate the Interval property in the left pane of the TrueDBGrid Designer and set it to Year.

In Code

Add the following code to the Form_Load event:

·      Visual Basic

' Set the GroupInfo.Interval of the HireDate column to Year.

Me.C1TrueDBGrid1.Columns("HireDate").GroupInfo.Interval = C1.Win.C1TrueDBGrid.GroupIntervalEnum.Year

·      C#

// Set the GroupInfo.Interval of the HireDate column to Year.

this.c1TrueDBGrid1.Columns["HireDate"].GroupInfo.Interval = C1.Win.C1TrueDBGrid.GroupIntervalEnum.Year;

·      Delphi

// Set the GroupInfo.Interval of the HireDate column to Year.

Self.C1TrueDBGrid1.Columns['HireDate'].GroupInfo.Interval := C1.Win.C1TrueDBGrid.GroupIntervalEnum.Year;

9.   Finally, to keep the HireDate column visible after grouping by it, set the ColumnVisible property to True.

In the Designer

Locate the ColumnVisible property in the left pane of the TrueDBGrid Designer and set it to True.

In Code

Add the following code to the Form_Load event:

·      Visual Basic

' Keep the HireDate column visible while grouping.

Me.C1TrueDBGrid1.Columns("HireDate").GroupInfo.ColumnVisible = True

·      C#

// Keep the HireDate column visible while grouping.

this.c1TrueDBGrid1.Columns["HireDate"].GroupInfo.ColumnVisible = true;

·      Delphi

// Keep the HireDate column visible while grouping.

Self.C1TrueDBGrid1.Columns['HireDate'].GroupInfo.ColumnVisible := True;

In this example, the HireDate column is grouped by year.


Send comments about this topic to ComponentOne.
Copyright © ComponentOne LLC. All rights reserved.