Back to Devexpress

GridView.CustomDrawFooter Event

windowsforms-devexpress-dot-xtragrid-dot-views-dot-grid-dot-gridview-8e7324d6.md

latest10.2 KB
Original Source

GridView.CustomDrawFooter Event

Enables you to paint the view footer manually.

Namespace : DevExpress.XtraGrid.Views.Grid

Assembly : DevExpress.XtraGrid.v25.2.dll

NuGet Packages : DevExpress.Win.Grid, DevExpress.Win.Navigation

Declaration

csharp
[DXCategory("CustomDraw")]
public event RowObjectCustomDrawEventHandler CustomDrawFooter
vb
<DXCategory("CustomDraw")>
Public Event CustomDrawFooter As RowObjectCustomDrawEventHandler

Event Data

The CustomDrawFooter event's data class is RowObjectCustomDrawEventArgs. The following properties provide information specific to this event:

PropertyDescription
AppearanceGets the painted element’s appearance settings. Inherited from CustomDrawEventArgs.
BoundsReturns a value specifying limits for the drawing area. Inherited from CustomDrawEventArgs.
CacheProvides methods to paint on drawing surfaces in GDI+ and DirectX modes. See DirectX hardware acceleration to learn more. Inherited from CustomDrawEventArgs.
GraphicsA GDI+ drawing surface. Use the CustomDrawEventArgs.Cache property instead if you enable the DirectX hardware acceleration. Inherited from CustomDrawEventArgs.
HandledGets or sets a value specifying whether an event was handled and that the default element painting is therefore not required. Inherited from CustomDrawEventArgs.
InfoGets an object containing information about the painted element. Inherited from CustomDrawObjectEventArgs.
PainterGets the painter object that provides the default element painting mechanism. Inherited from CustomDrawObjectEventArgs.
RowHandleGets the handle of the row whose corresponding element is being painted.

The event data class exposes the following methods:

MethodDescription
DefaultDraw()Performs default painting of an element. Inherited from CustomDrawEventArgs.
DrawHtml(HtmlTemplate, DxHtmlPainterContext, Action<DxHtmlPainterArgs>)Paints the required HTML template inside an element that raised this event. The context parameter allows you to assign an object that transfers mouse events to template elements. Inherited from CustomDrawEventArgs.
DrawHtml(HtmlTemplate, Action<DxHtmlPainterArgs>)Paints the required HTML template inside an element that raised this event. Inherited from CustomDrawEventArgs.

Remarks

The CustomDrawFooter event is raised each time the footer needs to be repainted. Handle it to paint the footer panel manually. See the Custom Painting Basics and Custom Painting Scenarios topics for information on using custom draw events.

Important

Do not change cell values, modify the control’s layout, or change the control’s object model in the events used for custom control painting. Actions that update the layout can cause the control to malfunction.

Example

In this example the Grid column footer is manually re-painted to display information on cell colors. To re-paint cells themselves, handle the GridView.CustomDrawCell event.

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

public static void CustomDrawFooter(GridControl gridControl, GridView gridView) {
    gridView.OptionsView.ShowFooter = true;
    gridView.FooterPanelHeight = 70;

    Color highPriority = Color.Green;
    Color normalPriority = Color.Orange;
    Color lowPriority = Color.Red;
    int markWidth = 16;

    // Handle this event to paint the footer panel manually
    gridView.CustomDrawFooter += (s, e) => {
        int offset = 5;
        e.DefaultDraw();
        Color color = highPriority;
        Rectangle markRectangle;
        string priorityText = " - High level";
        for (int i = 0; i < 3; i++) {
            if (i == 1) {
                color = normalPriority;
                priorityText = " - Normal level";
            }
            else if (i == 2) {
                color = lowPriority;
                priorityText = " - Low level";
            }
            markRectangle = new Rectangle(e.Bounds.X + offset, e.Bounds.Y + offset + (markWidth + offset) * i, markWidth, markWidth);
            e.Cache.FillEllipse(markRectangle.X, markRectangle.Y, markRectangle.Width, markRectangle.Height, color);
            e.Appearance.TextOptions.HAlignment = HorzAlignment.Near;
            e.Appearance.Options.UseTextOptions = true;
            e.Appearance.DrawString(e.Cache, priorityText, new Rectangle(markRectangle.Right + offset, markRectangle.Y, e.Bounds.Width, markRectangle.Height));
        }
    };
}
vb
Private Sub Form3_Load1(ByVal sender As Object, ByVal e As EventArgs)
    CustomDrawFooter(gridControl1, gridView1)
End Sub

Public Shared Sub CustomDrawFooter(ByVal gridControl As GridControl, ByVal gridView As GridView)
    gridView.OptionsView.ShowFooter = True
    gridView.FooterPanelHeight = 70

    Dim highPriority As Color = Color.Green
    Dim normalPriority As Color = Color.Orange
    Dim lowPriority As Color = Color.Red
    Dim markWidth As Integer = 16

    ' Handle this event to paint the footer panel manually
    AddHandler gridView.CustomDrawFooter, Sub(s, e)
        Dim offset As Integer = 5
        e.DefaultDraw()
        Dim color As Color = highPriority
        Dim markRectangle As Rectangle
        Dim priorityText As String = " - High level"
        For i As Integer = 0 To 2
            If i = 1 Then
                color = normalPriority
                priorityText = " - Normal level"
            ElseIf i = 2 Then
                color = lowPriority
                priorityText = " - Low level"
            End If
            markRectangle = New Rectangle(e.Bounds.X + offset, e.Bounds.Y + offset + (markWidth + offset) * i, markWidth, markWidth)
            e.Cache.FillEllipse(markRectangle.X, markRectangle.Y, markRectangle.Width, markRectangle.Height, color)
            e.Appearance.TextOptions.HAlignment = HorzAlignment.Near
            e.Appearance.Options.UseTextOptions = True
            e.Appearance.DrawString(e.Cache, priorityText, New Rectangle(markRectangle.Right + offset, markRectangle.Y, e.Bounds.Width, markRectangle.Height))
        Next i
    End Sub
End Sub

See Also

CustomDrawFooterCell

Custom Painting Basics

Custom Painting Scenarios

Elements that Can Be Custom Painted

Manually Invalidating Controls

GridView Class

GridView Members

DevExpress.XtraGrid.Views.Grid Namespace