ComponentOne True DBGrid for WinForms
How to Use Splits / Horizontal Scrolling and Fixed Columns
In This Topic
    Horizontal Scrolling and Fixed Columns
    In This Topic

    Scrolling is independent for each split. Often, one or more columns need to be prevented from scrolling horizontally or vertically so that the columns will always be in view. True DBGrid for WinForms provides an easy way to keep any number of columns from scrolling at any location within the grid (even in the middle!) by setting a few split properties.

    As an example, with a grid with three horizontal splits, the following code will "fix" columns 0 and 1 in the middle split:

    To write code in Visual Basic

    Visual Basic
    Copy Code
    ' Hide all columns in Splits(1) except for columns 0 and 1.
    Dim Cols As C1TrueDBGrid.C1DisplayColumnCollection
    Dim C As C1TrueDBGrid.C1DisplayColumn
     
    Cols = Me.C1TrueDBGrid1.Splits(1).DisplayColumns
    For Each C In Cols
        C.Visible = False
    Next C
    Cols(0).Visible = True
    Cols(1).Visible = True
     
    ' Configure Splits(1) to display exactly two columns, and disableresizing.
    With Me.C1TrueDBGrid1.Splits(1)
        .SplitSizeMode = SizeModeEnum.NumberOfColumns
        .SplitSize = 2
        .AllowHorizontalSizing = False
    End With
    

    To write code in C#

    C#
    Copy Code
    // Hide all columns in Splits[1] except for columns 0 and 1.
    C1TrueDBGrid.C1DisplayColumnCollection Cols;
    C1TrueDBGrid.C1DisplayColumn C;
     
    Cols = this.c1TrueDBGrid1.Splits[1].DisplayColumns
    foreach (C In Cols)
    {
        C.Visible = false;
    }
    Cols(0).Visible = true;
    Cols(1).Visible = true;
     
    // Configure Splits[1] to display exactly two columns, and disable resizing.
    this.c1TrueDBGrid1.Splits[1].SplitSizeMode = SizeModeEnum.NumberOfColumns;
    this.c1TrueDBGrid1.Splits[1].SplitSize = 2;
    this.c1TrueDBGrid1.Splits[1].AllowHorizontalSizing = false;
    

    Usually, if columns 0 and 1 are kept from scrolling in one split, it will be desirable to have them invisible in the other splits:

    To write code in Visual Basic

    Visual Basic
    Copy Code
    ' Make columns 0 and 1 invisible in splits 0 and 2.
    Dim Cols As C1TrueDBGrid.C1DisplayColumnCollection
    Cols = Me.C1TrueDBGrid1.Splits(0).DisplayColumns
    Cols(0).Visible = False
    Cols(1).Visible = False
    Cols = Me.C1TrueDBGrid1.Splits(2).DisplayColumns
    Cols(0)Visible = False
    Cols(1)Visible = False
    

    To write code in C#

    C#
    Copy Code
    // Make columns 0 and 1 invisible in splits 0 and 2.
    C1TrueDBGrid.C1DisplayColumnCollection Cols;
    Cols = this.c1TrueDBGrid1.Splits[0].DisplayColumns;
    Cols[0].Visible = false;
    Cols[1].Visible = false;
    Cols = this.c1TrueDBGrid1.Splits[2].DisplayColumns;
    Cols[0]Visible = false;
    Cols[1]Visible = false;
    
    See Also