ComponentOne True DBGrid for WinForms
True DBGrid for WinForms Tutorials / Tutorial 14: Creating a Grid with Fixed, Nonscrolling Columns
In This Topic
    Tutorial 14: Creating a Grid with Fixed, Nonscrolling Columns
    In This Topic

    Often, you would like to prevent one or more columns from scrolling horizontally or vertically so that they will always be in view. The SplitCollection of True DBGrid provides a generalized mechanism for defining groups of adjacent columns, and can be used to implement any number of fixed, nonscrolling columns or rows. In this tutorial, you will learn how to write code to create a grid with two horizontal splits, and then "fix" a pair of columns in the leftmost split.

    Complete the following steps:

    1. Follow Tutorial 1: Binding True DBGrid to a DataSet to create a project with a C1TrueDBGrid bound to a DataSet.
    2. In the Load event for Form1, place the following code to create an additional split and to fix columns 0 and 1 in the leftmost split:

      To write code in Visual Basic

      Visual Basic
      Copy Code
      Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
          ' Create an additional split.
          Me.C1TrueDBGrid1.InsertHorizontalSplit(0)
       
          ' Hide all columns in the leftmost split except 0 and 1.
          Dim x As Integer
          For x = 2 To Me.C1TrueDBGrid1.Columns.Count - 1
              Me.C1TrueDBGrid1.Splits(0).DisplayColumns(x).Visible = False
          Next
       
          ' Configure split 0 to display exactly 2 columns.
          With Me.C1TrueDBGrid1.Splits(0)
              .SplitSizeMode = C1.Win.C1TrueDBGrid.SizeModeEnum.NumberOfColumns
              .SplitSize = 2
              .AllowHorizontalSizing = False
          End With
       
          ' Make columns 0 and 1 invisible in split 1.
          Me.C1TrueDBGrid1.Splits(1).DisplayColumns(0).Visible = False
          Me.C1TrueDBGrid1.Splits(1).DisplayColumns(1).Visible = False
       
          ' Turn off record selectors in split 1.
          Me.C1TrueDBGrid1.Splits(1).RecordSelectors = False
      End Sub
      

      To write code in C#

      C#
      Copy Code
      private void Form1_Load(System.object sender,  System.EventArgs e) 
      {
          // Create an additional split.
          this.c1TrueDBGrid1.InsertHorizontalSplit(0);
       
          // Hide all columns in the leftmost split except 0 and 1.
          int x;
          for (x = 2 ; x < this.c1TrueDBGrid1.Columns.Count; x++)
          {
              this.c1TrueDBGrid1.Splits[0].DisplayColumns[x].Visible = false;
          }
       
          // Configure split 0 to display exactly 2 columns.
          this.c1TrueDBGrid1.Splits[0].SplitSizeMode = C1.Win.C1TrueDBGrid.SizeModeEnum.NumberOfColumns;
          this.c1TrueDBGrid1.Splits[0].SplitSize = 2;
          this.c1TrueDBGrid1.Splits[0].AllowHorizontalSizing = false;
       
          // Make columns 0 and 1 invisible in split 1.
          this.c1TrueDBGrid1.Splits[1].DisplayColumns[0].Visible = false;
          this.c1TrueDBGrid1.Splits[1].DisplayColumns[1].Visible = false;
       
          // Turn off record selectors in split 1.
          this.c1TrueDBGrid1.Splits[1].RecordSelectors = false;
      }
      

    Run the program and observe the following:

    Use splits to create fixed, non-scrolling columns anywhere within the grid – even in the middle. Also use splits to present different views of data. For example, splits can be created that scroll independently (in the vertical direction) so that users may compare records at the beginning of the database with those at the end. For more information, see How to Use Splits.

    You've successfully completed creating a grid with fixed, nonscrolling columns; this concludes tutorial 14.