Back to Devexpress

GridView.CustomDrawGroupPanel Event

windowsforms-devexpress-dot-xtragrid-dot-views-dot-grid-dot-gridview-dc8018bc.md

latest8.0 KB
Original Source

GridView.CustomDrawGroupPanel Event

Enables you to paint the group panel 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 CustomDrawEventHandler CustomDrawGroupPanel
vb
<DXCategory("CustomDraw")>
Public Event CustomDrawGroupPanel As CustomDrawEventHandler

Event Data

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

PropertyDescription
AppearanceGets the painted element’s appearance settings.
BoundsReturns a value specifying limits for the drawing area.
CacheProvides methods to paint on drawing surfaces in GDI+ and DirectX modes. See DirectX hardware acceleration to learn more.
GraphicsA GDI+ drawing surface. Use the CustomDrawEventArgs.Cache property instead if you enable the DirectX hardware acceleration.
HandledGets or sets a value specifying whether an event was handled and that the default element painting is therefore not required.

The event data class exposes the following methods:

MethodDescription
DefaultDraw()Performs default painting of an element.
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.
DrawHtml(HtmlTemplate, Action<DxHtmlPainterArgs>)Paints the required HTML template inside an element that raised this event.

Remarks

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

Note

After the CustomDrawGroupPanel event handler has been executed, the string specified by the GridView.GroupPanelText property is painted within the group panel, regardless of the event’s CustomDrawEventArgs.Handled parameter. To prevent this, set the GridView.GroupPanelText property to an empty string.

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 GridView.CustomDrawGroupPanel event is handled to perform group panel custom painting. The panel is filled with a gradient brush. Then an image is painted at the panel’s right edge.

csharp
Image groupPanelImage;

private void Form1_Load(object sender, EventArgs e) {
    groupPanelImage = Image.FromFile(@"C:\Work\Pictures\Icon.png");
    gridView1.Appearance.GroupPanel.ForeColor = Color.Black;
}

private void gridView1_CustomDrawGroupPanel(object sender, DevExpress.XtraGrid.Views.Base.CustomDrawEventArgs e) {
    //Define a linear gradient brush
    Color color1 = Color.FromArgb(244, 132, 38);
    Brush brush = e.Cache.GetGradientBrush(e.Bounds, color1, Color.Bisque,
      System.Drawing.Drawing2D.LinearGradientMode.Horizontal);
    //Fill the group panel
    e.Cache.FillRectangle(brush, e.Bounds);
    //Draw a custom image at the panel's right edge
    Rectangle r = new Rectangle(e.Bounds.X + e.Bounds.Width - groupPanelImage.Size.Width - 5,
      e.Bounds.Y + (e.Bounds.Height - groupPanelImage.Size.Height) / 2, groupPanelImage.Width, groupPanelImage.Height);
    e.Cache.DrawImageUnscaled(groupPanelImage, r);
    e.Handled = true;
}
vb
Dim groupPanelImage As Image

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    groupPanelImage = Image.FromFile("C:\Work\Pictures\Icon.png")
    GridView1.Appearance.GroupPanel.ForeColor = Color.Black
End Sub

Private Sub GridView1_CustomDrawGroupPanel(sender As Object, e As DevExpress.XtraGrid.Views.Base.CustomDrawEventArgs) Handles GridView1.CustomDrawGroupPanel
    'Define a linear gradient brush
    Dim color1 As Color = Color.FromArgb(244, 132, 38)
    Dim brush As Brush = e.Cache.GetGradientBrush(e.Bounds, color1, Color.Bisque, LinearGradientMode.Horizontal)
    'Fill the group panel
    e.Cache.FillRectangle(brush, e.Bounds)
    'Draw a custom image at the panel's right edge
    Dim r As Rectangle = New Rectangle(e.Bounds.X + e.Bounds.Width - groupPanelImage.Size.Width - 5,
       e.Bounds.Y + (e.Bounds.Height - groupPanelImage.Size.Height) / 2, groupPanelImage.Width, groupPanelImage.Height)
    e.Cache.DrawImageUnscaled(groupPanelImage, r)
    e.Handled = True
End Sub

See Also

Custom Painting Basics

Custom Painting Scenarios

Elements that Can Be Custom Painted

Manually Invalidating Controls

GridView Class

GridView Members

DevExpress.XtraGrid.Views.Grid Namespace