假设“Order Date”列包含了日期/时间值。 如果视图的 GridOptionsView.AllowCellMerge 选项被设置为 true,则该列的有相同日期/时间值的相邻单元格将被合并 (取值的日期和时间部分都应该相等)。 下面的示例展示了如何合并列的单元格,这些单元格有相同的日期部分,但是时间部分可能有不同的取值。 为了重写默认的单元格合并机制,接管了 GridView.CellMerge 事件。

C#CopyCode image复制代码
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;
   }
}

Visual BasicCopyCode image复制代码
Imports DevExpress.XtraGrid.Views.Grid
' ...
Private Sub GridView1_CellMerge(ByVal sender As Object, _
ByVal e As CellMergeEventArgs) Handles GridView1.CellMerge
   If (e.Column.FieldName = "Order Date") Then
      Dim view As GridView = CType(sender, GridView)
      Dim val1 As DateTime = view.GetRowCellValue(e.RowHandle1, e.Column)
      Dim val2 As DateTime = view.GetRowCellValue(e.RowHandle2, e.Column)
      e.Merge = (val1.Date = val2.Date)
      e.Handled = True
   End If
End Sub