Back to Devexpress

VGridControlBase.CustomDrawRowHeaderCell Event

windowsforms-devexpress-dot-xtraverticalgrid-dot-vgridcontrolbase-11dbbf53.md

latest13.9 KB
Original Source

VGridControlBase.CustomDrawRowHeaderCell Event

Enables row header cells to be painted manually.

Namespace : DevExpress.XtraVerticalGrid

Assembly : DevExpress.XtraVerticalGrid.v25.2.dll

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

Declaration

csharp
public event CustomDrawRowHeaderCellEventHandler CustomDrawRowHeaderCell
vb
Public Event CustomDrawRowHeaderCell As CustomDrawRowHeaderCellEventHandler

Event Data

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

PropertyDescription
AllowGlyphSkinningGets or sets whether this row header cell’s icon can be painted with a foreground color.
AllowHtmlTextGets or sets whether the row caption can be formatted using HTML tags.
AppearanceGets the painted element’s appearance settings. Inherited from CustomDrawEventArgs.
BoundsGets a value specifying limits for the drawing area. Inherited from CustomDrawEventArgs.
CacheGets an object which specifies the storage for the most used pens, fonts and brushes. Inherited from CustomDrawEventArgs.
CaptionGets or sets the text displayed within the painted row header cell.
CaptionRectGets the bounding rectangle of the row header cell’s caption.
CellIndexGets the index of the painted row header cell.
FocusedGets a value indicating whether the painted row header cell has focus.
FocusRectGets the bounds of the focus rectangle around the row header cell.
GraphicsGets an object used to paint. Inherited from CustomDrawEventArgs.
HandledGets or sets a value specifying whether an event was handled, if handled, default actions are not required. Inherited from CustomDrawEventArgs.
HotTrackGets a value indicating whether the mouse pointer passes over the painted row header cell.
ImageIndexGets or sets the image displayed within the painted row header cell.
ImageRectGets the bounding rectangle within the painted row header cell where the image is to be drawn.
IsRightToLeftGets a value indicating whether the VGridControl‘s elements are aligned to support locales using right-to-left fonts. Inherited from CustomDrawEventArgs.
ObjectArgsGets an object containing information about the painted element. Inherited from CustomDrawEventArgs.
PainterGets the painter object that provides the default element’s painting mechanism. Inherited from CustomDrawEventArgs.
PressedGets a value indicating whether the painted row header cell is pressed.
PropertiesProvides properties specific to the row being custom painted. Inherited from CustomDrawRowEventArgs.
RowGets the row whose element is to be drawn. Inherited from CustomDrawRowEventArgs.
SelectedGets whether or not the current row is selected.

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 CustomDrawRowHeaderCell event is raised before a row header cell is painted. The cell that is going to be painted is identified by the event parameter’s CustomDrawRowHeaderCellEventArgs.CellIndex property. The row where the processed cell resides can be obtained via the CustomDrawRowEventArgs.Row property.

The CustomDrawRowHeaderCell event can be used for two purposes:

  • To manually paint all or only particular row header cells. The event parameter allows you to obtain the processed cell’s caption, state, whether it has focus, etc. Note that you need to set the CustomDrawEventArgs.Handled parameter to true to indicate that the default painting is not required for the cell.
  • Change the cell’s settings (image, style settings etc) and leave the CustomDrawEventArgs.Handled parameter set to false. This will paint the row header cell using the default mechanism but with modified settings.

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

The following sample code handles the VGridControlBase.CustomDrawRowHeaderCell, VGridControlBase.CustomDrawRowValueCell and VGridControlBase.CustomDrawSeparator events to custom paint cells in a multi-editor row.

csharp
using DevExpress.XtraVerticalGrid.Rows;

using System.Drawing.Drawing2D;
using DevExpress.XtraVerticalGrid.Events;

private void Form1_Load(object sender, EventArgs e) {
    vGridControl1.OptionsView.ShowRootLevelIndent = false;
    MultiEditorRow meRow = (vGridControl1.Rows[0] as MultiEditorRow);
    if (meRow != null) {
        meRow.SeparatorKind = SeparatorKind.String;
        meRow.SeparatorString = "/";
    }
}

Font fontRegular = new Font("Tahoma", 10);
Font fontBold = new Font("Tahoma", 10, FontStyle.Bold);

private void vGridControl1_CustomDrawSeparator(object sender, DevExpress.XtraVerticalGrid.Events.CustomDrawSeparatorEventArgs e) {
   Font font = fontRegular;
    Brush brush = Brushes.Orange;
    if(e.IsHeaderSeparator) {
        font = fontBold;
        brush = Brushes.LightGray;
    }
    e.Cache.FillRectangle(brush, e.Bounds);
    e.Cache.DrawString("/", font, Brushes.DarkBlue, e.Bounds, e.Appearance.GetStringFormat());
    e.Handled = true;
}

private void vGridControl1_CustomDrawRowValueCell(object sender, DevExpress.XtraVerticalGrid.Events.CustomDrawRowValueCellEventArgs e) {
    e.Cache.FillRectangle(Brushes.Orange, Rectangle.Inflate(e.Bounds, 1, 1));
    e.Cache.DrawString(e.CellText, e.Appearance.Font, Brushes.Black, e.Bounds, e.Appearance.GetStringFormat());
    e.Handled = true;
}

private void vGridControl1_CustomDrawRowHeaderCell(object sender, DevExpress.XtraVerticalGrid.Events.CustomDrawRowHeaderCellEventArgs e) {
    Rectangle rect = Rectangle.Inflate(e.Bounds, 1, 1);
    Rectangle rectText = Rectangle.Inflate(e.Bounds, -2, 0);
    e.Cache.FillRectangle(Brushes.LightGray, rect);
    e.Cache.DrawString(e.Caption, e.Appearance.Font, Brushes.Black, rectText, e.Appearance.GetStringFormat());
    e.Handled = true;
}
vb
Imports DevExpress.XtraVerticalGrid.Rows

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    VGridControl1.OptionsView.ShowRootLevelIndent = False
    Dim meRow As MultiEditorRow = (TryCast(VGridControl1.Rows(0), MultiEditorRow))
    If Not meRow Is Nothing Then
        meRow.SeparatorKind = SeparatorKind.String
        meRow.SeparatorString = "/"
    End If
End Sub

Private fontRegular As Font = New Font("Tahoma", 10)
Private fontBold As Font = New Font("Tahoma", 10, FontStyle.Bold)

Private Sub VGridControl1_CustomDrawRowValueCell(sender As Object, e As DevExpress.XtraVerticalGrid.Events.CustomDrawRowValueCellEventArgs) Handles VGridControl1.CustomDrawRowValueCell
    e.Cache.FillRectangle(Brushes.Orange, Rectangle.Inflate(e.Bounds, 1, 1))
    e.Cache.DrawString(e.CellText, e.Appearance.Font, Brushes.Black, e.Bounds, e.Appearance.GetStringFormat())
    e.Handled = True
End Sub

Private Sub VGridControl1_CustomDrawRowHeaderCell(sender As Object, e As DevExpress.XtraVerticalGrid.Events.CustomDrawRowHeaderCellEventArgs) Handles VGridControl1.CustomDrawRowHeaderCell
    Dim rect As Rectangle = Rectangle.Inflate(e.Bounds, 1, 1)
    Dim rectText As Rectangle = Rectangle.Inflate(e.Bounds, -2, 0)
    e.Cache.FillRectangle(Brushes.LightGray, rect)
    e.Cache.DrawString(e.Caption, e.Appearance.Font, Brushes.Black, rectText, e.Appearance.GetStringFormat())
    e.Handled = True
End Sub

Private Sub VGridControl1_CustomDrawSeparator(sender As Object, e As DevExpress.XtraVerticalGrid.Events.CustomDrawSeparatorEventArgs) Handles VGridControl1.CustomDrawSeparator
    Dim font As Font = fontRegular
    Dim brush As Brush = Brushes.Orange
    If e.IsHeaderSeparator Then
        font = fontBold
        brush = Brushes.LightGray
    End If
    e.Cache.FillRectangle(brush, e.Bounds)
    e.Cache.DrawString("/", font, Brushes.DarkBlue, e.Bounds, e.Appearance.GetStringFormat())
    e.Handled = True
End Sub

See Also

AppearanceHeader

Custom Painting

Custom Painting Samples

VGridControlBase Class

VGridControlBase Members

DevExpress.XtraVerticalGrid Namespace