ComponentOne True DBGrid for .NET (2.0) Search HelpCentral 

Group Rows by the First Character of the Value

This topic demonstrates how to use the GroupIntervalEnum.Alphabetical 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 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 Products table and type "Products" 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.ProductsTableAdapter.Fill(Me.Products._Products)

·      C#

this.ProductsTableAdapter.Fill(this.Products._Products);

·      Delphi

Self.ProductsTableAdapter.Fill(Self.Products._Products);

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 ProductName column by clicking on it in the right pane.

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

8.   Set the Interval property to Alphabetical.

In the Designer

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

In Code

Add the following code to the Form_Load event:

·      Visual Basic

' Set the GroupInfo.Interval of the ProductName column to Alphabetical.

Me.C1TrueDBGrid1.Columns("ProductName").GroupInfo.Interval = C1.Win.C1TrueDBGrid.GroupIntervalEnum.Alphabetical

·      C#

// Set the GroupInfo.Interval of the ProductName column to Alphabetical.

this.c1TrueDBGrid1.Columns["ProductName"].GroupInfo.Interval = C1.Win.C1TrueDBGrid.GroupIntervalEnum.Alphabetical;

·      Delphi

// Set the GroupInfo.Interval of the ProductName column to Alphabetical.

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

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

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

·      C#

// Keep the ProductName column visible while grouping.

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

·      Delphi

// Keep the ProductName column visible while grouping.

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

In this example, the ProductName column is grouped by the first letter of the product name.


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