Export (0) Print
Expand All

DataGridViewRowPrePaintEventArgs Class

Provides data for the RowPrePaint event.

System.Object
  System.EventArgs
    System.ComponentModel.HandledEventArgs
      System.Windows.Forms.DataGridViewRowPrePaintEventArgs

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

'Declaration
Public Class DataGridViewRowPrePaintEventArgs _
	Inherits HandledEventArgs

The DataGridViewRowPrePaintEventArgs type exposes the following members.

  NameDescription
Public methodDataGridViewRowPrePaintEventArgsInitializes a new instance of the DataGridViewRowPrePaintEventArgs class.
Top

  NameDescription
Public propertyClipBoundsGets or sets the area of the DataGridView that needs to be repainted.
Public propertyErrorTextGets a string that represents an error message for the current DataGridViewRow.
Public propertyGraphicsGets the Graphics used to paint the current DataGridViewRow.
Public propertyHandledGets or sets a value that indicates whether the event handler has completely handled the event or whether the system should continue its own processing. (Inherited from HandledEventArgs.)
Public propertyInheritedRowStyleGets the cell style applied to the row.
Public propertyIsFirstDisplayedRowGets a value indicating whether the current row is the first row currently displayed in the DataGridView.
Public propertyIsLastVisibleRowGets a value indicating whether the current row is the last visible row in the DataGridView.
Public propertyPaintPartsThe cell parts that are to be painted.
Public propertyRowBoundsGet the bounds of the current DataGridViewRow.
Public propertyRowIndexGets the index of the current DataGridViewRow.
Public propertyStateGets the state of the current DataGridViewRow.
Top

  NameDescription
Public methodDrawFocusDraws the focus rectangle around the specified bounds.
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodPaintCellsPaints the specified cell parts for the area in the specified bounds.
Public methodPaintCellsBackgroundPaints the cell backgrounds for the area in the specified bounds.
Public methodPaintCellsContentPaints the cell contents for the area in the specified bounds.
Public methodPaintHeader(Boolean)Paints the entire row header of the current DataGridViewRow.
Public methodPaintHeader(DataGridViewPaintParts)Paints the specified parts of the row header of the current row.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

The RowPrePaint event occurs before a row is painted on a DataGridView control. RowPrePaint enables you to manually adjust the appearance of the row before any of the cells in the row are painted. This is useful if you want to customize the row, such as to produce a row where the content of one column spans multiple columns. Use the properties in DataGridViewRowPrePaintEventArgs to get the settings of the row without directly accessing the row in the DataGridView.

The following code example demonstrates how to handle the RowPrePaint event to draw a custom background for selected cells. This code example is part of a larger example provided in How to: Customize the Appearance of Rows in the Windows Forms DataGridView Control.

' Paints the custom selection background for selected rows. 
Sub dataGridView1_RowPrePaint(ByVal sender As Object, _
    ByVal e As DataGridViewRowPrePaintEventArgs) _
    Handles dataGridView1.RowPrePaint

    ' Do not automatically paint the focus rectangle.
    e.PaintParts = e.PaintParts And Not DataGridViewPaintParts.Focus

    ' Determine whether the cell should be painted with the  
    ' custom selection background. 
    If (e.State And DataGridViewElementStates.Selected) = _
        DataGridViewElementStates.Selected Then 

        ' Calculate the bounds of the row. 
        Dim rowBounds As New Rectangle( _
            Me.dataGridView1.RowHeadersWidth, e.RowBounds.Top, _
            Me.dataGridView1.Columns.GetColumnsWidth( _
            DataGridViewElementStates.Visible) - _
            Me.dataGridView1.HorizontalScrollingOffset + 1, _
            e.RowBounds.Height)

        ' Paint the custom selection background. 
        Dim backbrush As New _
            System.Drawing.Drawing2D.LinearGradientBrush(rowBounds, _
            Me.dataGridView1.DefaultCellStyle.SelectionBackColor, _
            e.InheritedRowStyle.ForeColor, _
            System.Drawing.Drawing2D.LinearGradientMode.Horizontal)
        Try
            e.Graphics.FillRectangle(backbrush, rowBounds)
        Finally
            backbrush.Dispose()
        End Try 
    End If 

End Sub 'dataGridView1_RowPrePaint

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft