GridView.CellMerge Event

Provides the ability to customize cell merging behavior.

Namespace: DevExpress.XtraGrid.Views.Grid

Assembly: DevExpress.XtraGrid.v20.1.dll

Declaration

[DXCategory("Merging")]
public event CellMergeEventHandler CellMerge
<DXCategory("Merging")>
Public Event CellMerge As CellMergeEventHandler

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

When the View's GridOptionsView.AllowCellMerge option is set to true the adjacent cells in each column are merged if they have matching values. For cells that have been merged in-place editors cannot be invoked.

The CellMerge event allows you to control how the cells are merged. For instance, it's possible to prevent cells in a specific column from being merged or to merge adjacent cells whose values do not match, etc.

The CellMerge event is called to decide whether two particular adjacent cells should be merged. To force cells to merge, set the CellMergeEventArgs.Merge and CellMergeEventArgs.Handled parameters to true. The CellMergeEventArgs.Handled parameter simply indicates that the current event call was handled and no default processing is required. If CellMergeEventArgs.Handled is left set to false the default merging mechanism will be invoked after your event handler is called (the cells will be merged if they have matching values).

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

Examples

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