How to Use Splits > Working with Columns in Splits |
Each split in a True DBGrid control maintains its own Columns collection. This provides tremendous flexibility for controlling the look and behavior of individual splits. The grid is connected to a single data source, so the splits just present different views of the same data. Therefore, the Columns collection in each split contains the same number of columns and the columns are bound to the same data fields.
Note that some Column object properties, such as Caption and DataField, have the same value in each split. These properties are said to be global. For example, given a grid with two splits, the following code will always print the same values for a given column index n:
Example Title |
Copy Code
|
---|---|
Debug.Print TDBGrid1.Splits(0).Columns(n).Caption Debug.Print TDBGrid1.Splits(1).Columns(n).Caption Debug.Print TDBGrid1.Columns(n).Caption |
More importantly, if you set any of the global properties of a column within a particular split, that property will be set to the same value for all splits. For example, the following code will append a column to all splits (not just the first one) and bind the columns to the same database field (LastName).
Example Title |
Copy Code
|
---|---|
Dim Cols As TrueDBGrid80.Columns Set Cols = TDBGrid1.Splits(0).Columns ' Append a column to the end of the Columns collection. Dim C As TrueDBGrid80.Column Set C = Cols.Add(Cols.Count) ' Set the DataField property of the newly created column. C.DataField = "LastName" |
However, the values of other Column object properties, such as Visible and BackColor, may vary from split to split. These properties are said to be split-specific. For example, a column created at run time is not visible by default. Thus, the LastName column created in the preceding example is invisible in all splits. The following code makes it visible in the second split:
Example Title |
Copy Code
|
---|---|
TDBGrid1.Splits(1).Columns("LastName").Visible = True
|
Since Visible is a split-specific property, the LastName column remains invisible in other splits.