How to: Custom Merge Cells

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;