This sample demonstrates dynamic(on the fly) merging of cells. It uses the derived classes, GridControl and GridModel to handle this task. For more static(predefined) merge cells, you have to set the properties as shown.
GridStyleInfo standardStyle = BaseStylesMap["Standard"].StyleInfo; standardStyle.MergeCell = GridMergeCellDirection.RowsInColumn;
GridStyleInfo rowHeaderStyle = BaseStylesMap["Row Header"].StyleInfo; rowHeaderStyle.MergeCell = GridMergeCellDirection.RowsInColumn;
We derive a class from a base class for overriding the existing methods of the base class to implement dynamic merging.
Features
Illustrates how to merge cells with the same value dynamically.
In this sample, the first three columns are filled with virtual data in OnQueryCellInfo method. The grid checks which cells have the same value using OnQueryCanMergeCells method and automatically merges those cells on the fly.
Changes in the columns are ignored because the value is always calculated in OnQueryCellInfo method.
The remaining columns contain regular cells where you can enter data and save them in the regular grid data object.
Entering the same value in neighboring cells will automatically merge them.
When you change the value of a cell within the merged range, the merged cells will automatically split, seperating the cell containing the changed value.
The sample also includes a technique to dynamically center the text in the current visible region of a merged cell which can be enabled through the custom property CenterTextInVisibleCellPart.