ComponentOne True DBGrid Pro 8
Tutorial 15 - Creating a Grid with Fixed, Nonscrolling Columns

Often, you would like to prevent one or more columns from scrolling horizontally so that they will always be in view. The Splits collection 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. In this tutorial, you will learn how to write code to create a grid with two splits, and then "fix" a pair of columns in the leftmost split.

1.   Follow steps 1 through 5 of Tutorial 1 to create a project with a TDBGrid bound to a Data control.

2.   In the Form_Load event, place the following code to create an additional split and to fix columns 0 and 1 in the leftmost split:

Example Title
Copy Code
Private Sub Form_Load()

    ' Before modifying the grid's properties, make sure the grid is

    ' initialized by refreshing the Data control.

    Data1.Refresh

 

    ' Create an additional split.

    Dim S As TrueDBGrid80.Split

    Set S = TDBGrid1.Splits.Add(0)

 

    ' Hide all columns in the leftmost split, Splits(0), except for columns 0 and 1.

    Dim C As TrueDBGrid80.Column

    Dim Cols As TrueDBGrid80.Columns

    Set Cols = TDBGrid1.Splits(0).Columns

    For Each C In Cols

        C.Visible = False

    Next C

    Cols(0).Visible = True

    Cols(1).Visible = True

 

    ' Configure Splits(0) to display exactly two columns, and disable resizing.

    With TDBGrid1.Splits(0)

        .SizeMode = dbgNumberOfColumns

        .Size = 2

        .AllowSizing = False

    End With

 

    ' Usually, if you fix columns 0 and 1 from scrolling  in a split, you will

    ' want to make them invisible in other splits.

    Set Cols = TDBGrid1.Splits(1).Columns

    Cols(0).Visible = False

    Cols(1).Visible = False

 

    ' Turn off the record selectors in Split 1.

    TDBGrid1.Splits(1).RecordSelectors = False

End Sub

Run the program and observe the following:

This concludes Tutorial 15.

 

 


Copyright (c) GrapeCity, inc. All rights reserved.

Product Support Forum  |  Documentation Feedback