假设 "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; } }
VB
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
本站文章除注明转载外,均为本站原创或翻译
欢迎任何形式的转载,但请务必注明出处,尊重他人劳动成果
转载请注明:文章转载自:DevExpress控件中文网 [https://www.devexpresscn.com/]
本文地址:https://www.devexpresscn.com/post/391.html
欢迎任何形式的转载,但请务必注明出处,尊重他人劳动成果
转载请注明:文章转载自:DevExpress控件中文网 [https://www.devexpresscn.com/]
本文地址:https://www.devexpresscn.com/post/391.html