Merging Cells

Another useful operation you may want to perform on a grid’s data is to merge cells with identical data. Figure 9.16 A shows a grid with duplicate data, and Figure 9.16 B shows the same grid after certain cells were merged. The MSFlexGrid control provides a mechanism for merging adjacent cells automatically if their contents happen to be identical. To control the merging of the cells with identical values, use the properties discussed in this section.

MergeCells Property This property determines whether adjacent cells will be merged; it can take one of the values shown in Table 9.12.

TABLE 9. 12
TABLE 9. 12
FIGURE 9.16 A:
FIGURE 9.16 A:
FIGURE 9.16 B:
FIGURE 9.16 B:

MergeRow() MergeCol() Properties Setting the MergeCells property to True doesn’t necessarily merged the cells to be merged, it must belong to a row or to a column and its MergeRow() or MergeCol() to property must be set to True. The MergeRow() and MergeCol() Properties are arrays that determine whether the cells of any given row or column can be merged. In other words, you can specify the rows and columns whose cells will be merged and through the MergeRow() and MergeCol() properties, have absolute control over the appearance of your grid. To merge consecutive cells on the first column-of the grid, use the following settings:

Gridl.MergeCol(1) = True
Gridl.MergeCells = 3

Likewise, if you want to merge consecutive cells that have identical contents on the grid’s first three rows, use the following settings:

Grid1.MergeRow(1) = True
Grid1.MergeRow(2) = True
Grid1.MergeRow (3) = True
Grid1.MergeCells = 2

Scroll to Top