Skip to main content

GridView.CellMerge Event

Allows you to manually merge cells.

Namespace: DevExpress.XtraGrid.Views.Grid

Assembly: DevExpress.XtraGrid.v24.1.dll

NuGet Packages: DevExpress.Win.Grid, DevExpress.Win.Navigation

Declaration

[DXCategory("Merging")]
public event CellMergeEventHandler CellMerge

Event Data

The CellMerge event's data class is CellMergeEventArgs. The following properties provide information specific to this event:

Property Description
CellValue1 Gets the value of the first cell being merged.
CellValue2 Gets the value of the second cell being merged.
Column Gets the column that contains the values to be merged.
Handled Gets or sets whether the cell merging operation is handled and therefore no default processing is required.
Merge Gets or sets whether two cells should be merged.
RowHandle1 Gets the handle of the row which contains the first of two cells that are to be merged.
RowHandle2 Gets the handle of the row which contains the second of two cells that are to be merged.

Remarks

The CellMerge event is raised if the View’s AllowCellMerge option is enabled.

Handle the CellMerge event to decide whether to merge two adjacent cells. To merge cells, set e.Merge and e.Handled event parameters to true. The e.Handled event parameter indicates that the default processing is not required. If the e.Handled parameter is set to false, the View uses the default merge mechanism (cells are merged if they have matching values).

To prevent cells from being merged, set e.Merge to false and e.Handled to true.

Read the following topics for additional information:

Example

Assume that the “Order Date” column contains date/time values. If the View’s GridOptionsView.AllowCellMerge option is set to true the column’s adjacent cells will be merged if they have matching date/time values (the date and time parts of the values should be equal). The following example shows how to merge the column’s cells which have matching date parts but may have different values for the time parts. To override the default cell merging mechanism the GridView.CellMerge event is handled.

using DevExpress.XtraGrid.Views.Grid;
// ...
private void gridView1_CellMerge(object sender, CellMergeEventArgs e) {
   if(e.Column.FieldName == "Order Date") {
      GridView view = sender as GridView;
      DateTime val1 = (DateTime)view.GetRowCellValue(e.RowHandle1, e.Column);
      DateTime val2 = (DateTime)view.GetRowCellValue(e.RowHandle2, e.Column);
      e.Merge = val1.Date == val2.Date;
      e.Handled = true;
   }
}
See Also