FlexGrid lets you enable automatic cell merging in the grid by setting the AllowMerging property to a value other than None. In addition, you need to set the AllowMerging property of each target row or column to true. Merging occurs only if adjacent cells contain the same non-empty string. There is no method to force a pair of cells to merge. The merging is done automatically based on the cell contents. This feature makes it easy to provide merged views of sorted data, where values in adjacent rows present repeated data.
Free auto-merge refers to merging of cells with just one pre-condition of having same values in adjacent cells. To automatically merge the cells in a row or a column, you simply need to set AllowMerging property of the C1FlexGrid class to Free and set AllowMerging property of the target row or column object to true.
Below code shows how to apply free merging on a WinForms FlexGrid column.
In most of the scenarios, you would want the grid to merge the grid cells with same values only if cells above or in left direction are also merged. This behavior is called restricted auto-merge and can be achieved by setting the C1FlexGrid.AllowMerging property to RestrictAll, RestrictRows or RestrictCols. This is required in addition to setting the AllowMerging property of target row or column to true.
Use the code below to allow restricted auto-merging on a WinForms FlexGrid column.
Merging the header cells, specially in case of multi-row header is another very common scenario used in grids and tables. To merge the header cells, you must set the C1FlexGrid.AllowMerging property to FixedOnly. You must also set the AllowMerging property of designated row and columns to true. In this case, headers cells with same value merge together to give a simplified appearance.
Following code demonstrates how to apply merging only on table headers of the WinForms FlexGrid.
FlexGrid also provides a Custom option through AllowMerging enumeration. In this case, auto-merge is performed on cell range collection provided using MergedRanges property of the C1FlexGrid class. The custom auto-merge is performed independent of cell content. For instance, below image shows the merging of two specified cell ranges despite of the different cell values.
Use the following code snippet to apply custom merge on the WinForms FlexGrid.