假设 "Order Date" 列中包含日期/时间值。如果视图的GridOptionsView.AllowCellMerge选项设置为true,若相邻两个单元格值是日期/时间值的话,这两个相邻单元格便会合并。下面的代码介绍了如何合并例单元格的日期部分,要覆盖默认的单元格合并机制,需要处理一下GridView.CellMerge事件。
C#
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; } }