Back to Devexpress

How to: Custom Draw Group Rows

windowsforms-3029-controls-and-libraries-data-grid-examples-painting-how-to-custom-draw-group-rows.md

latest1.7 KB
Original Source

How to: Custom Draw Group Rows

  • Nov 13, 2018

The code below applies grouping by the “Category_Name” column and changes the background and foreground colors for even group rows.

csharp
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid.Views.Base;
using DevExpress.XtraGrid.Views.Grid.ViewInfo;
using System.Drawing.Drawing2D;

private void Form3_Load1(object sender, EventArgs e) {
    CustomDrawGroupRow(gridControl1, gridView1);
}

public static void CustomDrawGroupRow(GridControl gridControl, GridView gridView) {
    gridView.Columns["Category_Name"].Group();

    // Handle this event to paint group rows manually
    gridView.CustomDrawGroupRow += (s, e) => {
        if (e.RowHandle % 2 == 0) {
            e.Appearance.BackColor = Color.BlanchedAlmond;
            e.Appearance.ForeColor = Color.DimGray; ;
        }
    };
}
vb
Imports DevExpress.XtraGrid.Views.Grid
Imports DevExpress.XtraGrid.Views.Base
Imports DevExpress.XtraGrid.Views.Grid.ViewInfo
Imports System.Drawing.Drawing2D

Private Sub Form3_Load1(ByVal sender As Object, ByVal e As EventArgs)
    CustomDrawGroupRow(gridControl1, gridView1)
End Sub

Public Shared Sub CustomDrawGroupRow(ByVal gridControl As GridControl, ByVal gridView As GridView)
    gridView.Columns("Category_Name").Group()

    ' Handle this event to paint group rows manually
    AddHandler gridView.CustomDrawGroupRow, Sub(s, e)
        If e.RowHandle Mod 2 = 0 Then
            e.Appearance.BackColor = Color.BlanchedAlmond
            e.Appearance.ForeColor = Color.DimGray

        End If
    End Sub
End Sub