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.
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
No comments:
Post a Comment