ComponentOne True DBGrid Pro 8
Data-sensitive Cell Merging

If the underlying grid data is sorted, you may be able to improve the readability of the display by grouping adjacent like-valued cells within the sorted column(s). The Merge property of the Column object controls whether its data cells are grouped in this manner to form a single non-editable cell. By default, this property is False, and each physical row within a column displays a data value, if any.

Consider the following grid, which is sorted on the Country field.

If data-sensitive cell merging is enabled for the Country column at run time, then its cells are grouped according to their contents:

Example Title
Copy Code
TDBGrid1.Columns("Country").Merge = True

Executing this statement produces the following display. Note that when the current cell is in the Country column, the marquee spans all like-valued rows and takes on the appearance of a dotted rectangle, regardless of the setting of the MarqueeStyle property. The behavior of the marquee in other columns is not affected, however.

If you have specified a design-time layout, you can achieve the same effect by setting the Merge property of the desired Column object within the Splits property page.

If the Merge property is True for a column, then none of its data cells can be edited, even if all rows contain unique values. The only exception to this is the AddNew row. However, once the new row is added to the underlying database, then its data will also be uneditable within the merged column(s).

You can use the Alignment and VerticalAlignment properties of the column's Style object to center the data within the merged cell, as in the following figure.

On the Splits property page, you can access these properties by expanding the Style property node at the same level of the tree as the Merge property. Or, in code:

Example Title
Copy Code
With TDBGrid1.Columns("Country").Style

    .Alignment = dbgCenter

    .VerticalAlignment = dbgVertCenter

End With

Note: Merged cells are not restricted to displaying text. You can also display bitmaps within merged cells by populating the ValueItems collection as described earlier in Specifying text-to-picture translations. The section Applying Pictures to Grid Elements describes a more flexible method for displaying in-cell graphics using Style objects.



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

Product Support Forum  |  Documentation Feedback