GrapeCity MultiRow Windows Forms Documentation
Automatic Merging of Cells

The GcMultiRow control provides a feature to perform automatic merging of cells, when the values of the cells placed in the row are the same in vertically adjacent rows.

Conditions for Merging

The following conditions must be met for the cells to be merged.

In the following figure, the cells other than Cell1, do not meet the conditions of merging.

Conditions for Merging

Cell Style

The style that is set for the top-most cell, is applied to the cells that have been merged.

Selection and Editing of Cells

If the GcMultiRow.MergedCellsSelectionMode property is set to All, all the merged cells are selected. In this case, if you edit the cells, all the merged cells are changed to the same value. If the GcMultiRow.MergedCellsSelectionMode property is set to Individually, the merged cells are selected one by one. In this case, you can change the value of each cell individually.

Selection of Merged Cells

Validation of Cells

If a validator is set in the merged cell, then the validator and the validation action is performed for the top-most cell, but the GcMultiRow.CellValidating event is fired for the current cell; therefore, if you want to use the automatic merge feature of the cells, it is recommended that you do not set different validators for the cells.

Specifying the Vertical Relationship

If cells that meet the merging conditions are present in the GcMultiRow control, the GcMultiRow.QueryCellMergeState event is fired. You can use this event to specify the vertical relationship for multiple cells, and restrict the merging of cells if the value of the cell above is different from that of the cell below.

Specifying the Vertical Relationship

Using Code

This example merges cells.

[VB]

Imports GrapeCity.Win.MultiRow 
Private Sub GcMultiRow1_QueryCellMergeState(sender As Object, e As QueryCellMergeStateEventArgs) Handles GcMultiRow1.QueryCellMergeState 
If e.ShouldMerge = True Then 
If Not e.QueryCell.CellIndex = 0 Then 
Dim newQueryCell As CellPosition = New CellPosition(e.QueryCell.RowIndex, e.QueryCell.CellIndex - 1) 
Dim newTargetCell As CellPosition = New CellPosition(e.TargetCell.RowIndex, e.TargetCell.CellIndex - 1) 
e.ShouldMerge = Me.GcMultiRow1.IsMerged(newQueryCell, newTargetCell) 
End If 
End If 
End Sub

[CS]

using GrapeCity.Win.MultiRow; 
void gcMultiRow1_QueryCellMergeState(object sender, QueryCellMergeStateEventArgs e) 
{ 
if (e.ShouldMerge == true) 
{ 
if (e.QueryCell.CellIndex != 0) 
{ 
CellPosition newQueryCell = new CellPosition(e.QueryCell.RowIndex, e.QueryCell.CellIndex - 1); 
CellPosition newTargetCell = new CellPosition(e.TargetCell.RowIndex, e.TargetCell.CellIndex - 1); 
e.ShouldMerge = this.gcMultiRow1.IsMerged(newQueryCell, newTargetCell); 
} 
} 
}

Limitations

See Also

 

 


Copyright © GrapeCity, inc. All rights reserved.

Support Options