How to Use Splits > Sizing and Scaling Splits |
True DBGrid gives you full control over the size and scaling of individual splits. You can configure a split to occupy an exact width, hold a fixed number of columns, or adjust its size proportionally in relation to other splits. If you are just starting out with True DBGrid, you can use splits in a variety of ways without having to master all of the details.
At run time, the actual size of a Split object depends upon its Size and SizeMode properties. The SizeMode property specifies the unit of measurement; the Size property specifies the number of units. True DBGrid supports three different sizing modes for splits, as determined by the setting of the SizeMode property:
0 - Scalable |
Size denotes relative width in relation to other splits. |
1 - Exact |
Size specifies a fixed width in container coordinates. |
2 - Number of Columns |
Size specifies a fixed number of columns. |
In code, you can use the constants dbgScalable, dbgExact, and dbgNumberOfColumns to refer to these settings.
A scalable split uses the value of its Size property to determine the percentage of space the split will occupy. For any scalable split, the percentage is determined by dividing its Size value by the sum of the Size values of all other scalable splits. Thus, you can consider the Size property of a scalable split to be the numerator of a fraction, the denominator of which is the sum of the scalable split sizes. Scalable splits compete for the space remaining after nonscalable splits have been allocated. By default, all splits are scalable, so they compete for the entire grid display region. SizeMode is always 0 - Scalable when a grid contains only one split.
An exact split uses the value of its Size property as its fixed width in container coordinates. Exact splits will be truncated if they will not fit within the horizontal grid boundaries. This mode is not applicable when a grid contains only one split.
A fixed-column split uses the Size property to indicate the exact number of columns that should always be displayed within the split. These splits automatically reconfigure the entire grid if the size of the displayed columns changes (either by code or user interaction), or if columns in the split are scrolled horizontally so that the widths of the displayed columns are different. This mode is primarily used to create fixed columns that do not scroll horizontally. However, it can be used for a variety of other purposes as well. This mode is not applicable when a grid contains only one split.
Note that when there is only one split (the grid's default behavior), the split spans the entire width of the grid, the SizeMode property is always 0 - Scalable, and the Size property is always 1. Setting either of these properties has no effect when there is only one split. If there are multiple splits, and you then remove all but one, the SizeMode and Size properties of the remaining split automatically revert to 0 and 1, respectively.
By default, the SizeMode property for a newly created split is 0 - Scalable, and the Size property is set to 1. For example, if you create two additional splits with the following code:
Example Title |
Copy Code
|
---|---|
Dim S As TrueDBGrid80.Split ' Create a Split at the left. Set S = TDBGrid1.Splits.Add(0) ' Create another. Set S = TDBGrid1.Splits.Add(0) |
the resulting grid display will look like this.
Notice that each split occupies 1/3 of the total grid space. This is because there are three scalable splits, and each split has a Size of 1. If you change the sizes of the splits to 1, 2, and 3, respectively:
Example Title |
Copy Code
|
---|---|
' Change relative size to 1. TDBGrid1.Splits(0).Size = 1 ' Change relative size to 2. TDBGrid1.Splits(1).Size = 2 ' Change relative size to 3. TDBGrid1.Splits(2).Size = 3 |
the resulting grid display will look like this.
Notice the sum of the split sizes (1+2+3) is 6, so the size of each split is a fraction with the numerator being the value of its Size property and a denominator of 6.
When a split's SizeMode is set to 1 - Exact, that split receives space before the other splits. This behavior is somewhat more complex, but understanding how scalable splits work is helpful. For example, assume that splits are set in the following way:
Example Title |
Copy Code
|
---|---|
Split0.SizeMode = dbgScalable Split0.Size = 1 Split1.SizeMode = dbgExact Split1.Size = 2500 Split2.SizeMode = dbgScalable Split2.Size = 2 |
After configuring the splits in this way, the resulting grid display will look like this.
The fixed-size split in the middle (Split1) is configured to exactly 2500 twips, and the remaining splits compete for the space remaining in the grid. Since the remaining splits are both scalable splits, they divide the remaining space among themselves according to the percentages calculated using their Size property values. So, the leftmost split occupies 1/3 of the remaining space, and the rightmost split occupies 2/3.
Splits with SizeMode set to 2 - Number of Columns behave almost identically to exact splits, except their size is determined by the width of an integral number of columns. The width, however, is dynamic, so resizing the columns or scrolling so that different columns are in view will cause the entire grid to reconfigure itself.
Avoid creating a grid with no scalable splits. Although True DBGrid handles this situation, it is difficult to work with a grid configured in this way. For example, if no splits are scalable, all splits will have an exact size, which may not fill the entire horizontal width of the grid. If the total width of the splits is too short, True DBGrid displays a "null-zone" where there are no splits. If the total width of the splits is wider than the grid, then True DBGrid will show only the separator lines for the splits that cannot be shown.