DataGridViewRowPostPaintEventArgs Class

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Provides data for the RowPostPaint event.

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

System.Object
  System.EventArgs
    System.Windows.Forms.DataGridViewRowPostPaintEventArgs

Public Class DataGridViewRowPostPaintEventArgs
	Inherits EventArgs

NameDescription
System_CAPS_pubpropertyClipBounds

Gets or sets the area of the DataGridView that needs to be repainted.

System_CAPS_pubpropertyErrorText

Gets a string that represents an error message for the current DataGridViewRow.

System_CAPS_pubpropertyGraphics

Gets the Graphics used to paint the current DataGridViewRow.

System_CAPS_pubpropertyInheritedRowStyle

Gets the cell style applied to the current DataGridViewRow.

System_CAPS_pubpropertyIsFirstDisplayedRow

Gets a value indicating whether the current row is the first row displayed in the DataGridView.

System_CAPS_pubpropertyIsLastVisibleRow

Gets a value indicating whether the current row is the last visible row displayed in the DataGridView.

System_CAPS_pubpropertyRowBounds

Get the bounds of the current DataGridViewRow.

System_CAPS_pubpropertyRowIndex

Gets the index of the current DataGridViewRow.

System_CAPS_pubpropertyState

Gets the state of the current DataGridViewRow.

NameDescription
System_CAPS_pubmethodDrawFocus(Rectangle, Boolean)

Draws the focus rectangle around the specified bounds.

System_CAPS_pubmethodEquals(Object)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_protmethodFinalize()

Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_protmethodMemberwiseClone()

Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_pubmethodPaintCells(Rectangle, DataGridViewPaintParts)

Paints the specified cell parts for the area in the specified bounds.

System_CAPS_pubmethodPaintCellsBackground(Rectangle, Boolean)

Paints the cell backgrounds for the area in the specified bounds.

System_CAPS_pubmethodPaintCellsContent(Rectangle)

Paints the cell contents for the area in the specified bounds.

System_CAPS_pubmethodPaintHeader(Boolean)

Paints the entire row header of the current DataGridViewRow.

System_CAPS_pubmethodPaintHeader(DataGridViewPaintParts)

Paints the specified parts of the row header of the current row.

System_CAPS_pubmethodToString()

Returns a string that represents the current object.(Inherited from Object.)

The RowPostPaint event occurs after a row is painted on a DataGridView control. RowPostPaint allows you to manually adjust the appearance of the row after the cells in the row are painted. This is useful if you want to customize the row.

The following code example demonstrates how to handle the RowPostPaint event to make the content of a cell span the entire row. 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 content that spans multiple columns and the focus rectangle.
Sub dataGridView1_RowPostPaint(ByVal sender As Object, _
    ByVal e As DataGridViewRowPostPaintEventArgs) _
    Handles dataGridView1.RowPostPaint

    ' 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)

    Dim forebrush As SolidBrush = Nothing
    Try
        ' Determine the foreground color.
        If (e.State And DataGridViewElementStates.Selected) = _
            DataGridViewElementStates.Selected Then

            forebrush = New SolidBrush(e.InheritedRowStyle.SelectionForeColor)
        Else
            forebrush = New SolidBrush(e.InheritedRowStyle.ForeColor)
        End If

        ' Get the content that spans multiple columns.
        Dim recipe As Object = _
            Me.dataGridView1.Rows.SharedRow(e.RowIndex).Cells(2).Value

        If (recipe IsNot Nothing) Then
            Dim text As String = recipe.ToString()

            ' Calculate the bounds for the content that spans multiple 
            ' columns, adjusting for the horizontal scrolling position 
            ' and the current row height, and displaying only whole
            ' lines of text.
            Dim textArea As Rectangle = rowBounds
            textArea.X -= Me.dataGridView1.HorizontalScrollingOffset
            textArea.Width += Me.dataGridView1.HorizontalScrollingOffset
            textArea.Y += rowBounds.Height - e.InheritedRowStyle.Padding.Bottom
            textArea.Height -= rowBounds.Height - e.InheritedRowStyle.Padding.Bottom
            textArea.Height = (textArea.Height \ e.InheritedRowStyle.Font.Height) * _
                e.InheritedRowStyle.Font.Height

            ' Calculate the portion of the text area that needs painting.
            Dim clip As RectangleF = textArea
            clip.Width -= Me.dataGridView1.RowHeadersWidth + 1 - clip.X
            clip.X = Me.dataGridView1.RowHeadersWidth + 1
            Dim oldClip As RectangleF = e.Graphics.ClipBounds
            e.Graphics.SetClip(clip)

            ' Draw the content that spans multiple columns.
            e.Graphics.DrawString(text, e.InheritedRowStyle.Font, forebrush, _
                textArea)

            e.Graphics.SetClip(oldClip)
        End If
    Finally
        forebrush.Dispose()
    End Try

    If Me.dataGridView1.CurrentCellAddress.Y = e.RowIndex Then
        ' Paint the focus rectangle.
        e.DrawFocus(rowBounds, True)
    End If

End Sub 'dataGridView1_RowPostPaint

.NET Framework
Available since 2.0

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

Return to top
Show: