ComponentOne True DBGrid for WinForms
Data Presentation Techniques / Column Grouping / Column Grouping with the GroupIntervalEnum Enumeration / Group Rows by Year
In This Topic
    Group Rows by Year
    In This Topic

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

    Complete the following steps:

    1. Start a new .NET project.
    2. Navigate to the Visual Studio Toolbox and add a C1TrueDBGrid control to the form.
    3. Click the C1TrueDBGrid 's smart tag to open the C1TrueDBGrid Tasks menu, click the drop-down arrow in the Choose Data Source box and choose Add Project Data Source.
    4. In the Data Source Configuration Wizard, either select a connection to C1NWind.mdb or create a new connection to this database.
    5. 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.
    6. Visual Studio adds the following code to the Form_Load event:

      To write code in Visual Basic

      Visual Basic
      Copy Code
      Me.EmployeesTableAdapter.Fill(Me.Employees._Employees)
      

      To write code in C#

      C#
      Copy Code
      this.employeesTableAdapter.Fill(this.Employees._Employees);
      
    7. 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:

      To write code in Visual Basic

      Visual Basic
      Copy Code
      Me.C1TrueDBGrid1.DataView = C1.Win.C1TrueDBGrid.DataViewEnum.GroupBy
      

      To write code in C#

      C#
      Copy Code
      this.c1TrueDBGrid1.DataView = C1.Win.C1TrueDBGrid.DataViewEnum.GroupBy;
      
    8. Open the C1TrueDBGrid Designer by selecting Designer from the C1TrueDBGrid Tasks menu.
    9. 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.


    10. Set the Interval property to GroupIntervalEnum.Year.

      In the Designer

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


      In Code

      Add the following code to the Form_Load event:

      To write code in Visual Basic

      Visual Basic
      Copy Code
      ' Set the GroupInfo.Interval of the HireDate column to Year.
      Me.C1TrueDBGrid1.Columns("HireDate").GroupInfo.Interval = C1.Win.C1TrueDBGrid.GroupIntervalEnum.Year
      

      To write code in C#

      C#
      Copy Code
      // Set the GroupInfo.Interval of the HireDate column to Year.
      this.c1TrueDBGrid1.Columns["HireDate"].GroupInfo.Interval = C1.Win.C1TrueDBGrid.GroupIntervalEnum.Year;
      
    11. 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 C1TrueDBGrid Designer and set it to True.


      In Code

      Add the following code to the Form_Load event:

      To write code in Visual Basic

      Visual Basic
      Copy Code
      ' Keep the HireDate column visible while grouping.
      Me.C1TrueDBGrid1.Columns("HireDate").GroupInfo.ColumnVisible = True
      

      To write code in C#

      C#
      Copy Code
      // Keep the HireDate column visible while grouping.
      this.c1TrueDBGrid1.Columns["HireDate"].GroupInfo.ColumnVisible = true;
      

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


    See Also