ComponentOne True DBGrid for .NET (2.0) Search HelpCentral 

Group Rows by Date Value (Outlook-Style)

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

Note: The Nwind.mdb database was modified for this example. A field NextMeeting was added to the employees table and filled in with more current dates.

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 adapter’s 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 NextMeeting column by clicking on it in the right pane.

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

8.   Set the Interval property to GroupIntervalEnum.DateSpan.

In the Designer

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

In Code

Add the following code to the Form_Load event:

·      Visual Basic

' Set the GroupInfo.Interval of the grid to DateSpan.

Me.C1TrueDBGrid1.Columns("NextMeeting").GroupInfo.Interval = C1.Win.C1TrueDBGrid.GroupIntervalEnum.DateSpan

·      C#

// Set the GroupInfo.Interval of the grid to DateSpan.

this.c1TrueDBGrid1.Columns["NextMeeting"].GroupInfo.Interval = C1.Win.C1TrueDBGrid.GroupIntervalEnum.DateSpan;

·      Delphi

// Set the GroupInfo.Interval of the grid to DateSpan.

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

9.   Finally, to keep the NextMeeting 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 NextMeeting column visible while grouping.

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

·      C#

// Keep the NextMeeting column visible while grouping.

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

·      Delphi

// Keep the NextMeeting column visible while grouping.

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

In this example, the NextMeeting column is sorted by date values.


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