DataGridViewRowPrePaintEventArgs Class
TOC
Collapse the table of content
Expand the table of content

DataGridViewRowPrePaintEventArgs Class

 

Provides data for the RowPrePaint event.

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

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

public class DataGridViewRowPrePaintEventArgs : HandledEventArgs

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_pubpropertyHandled

Gets 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.)

System_CAPS_pubpropertyInheritedRowStyle

Gets the cell style applied to the row.

System_CAPS_pubpropertyIsFirstDisplayedRow

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

System_CAPS_pubpropertyIsLastVisibleRow

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

System_CAPS_pubpropertyPaintParts

The cell parts that are to be painted.

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 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.
void dataGridView1_RowPrePaint(object sender,
        DataGridViewRowPrePaintEventArgs e)
{
    // Do not automatically paint the focus rectangle.
    e.PaintParts &= ~DataGridViewPaintParts.Focus;

    // Determine whether the cell should be painted
    // with the custom selection background.
    if ((e.State & DataGridViewElementStates.Selected) ==
                DataGridViewElementStates.Selected)
    {
        // Calculate the bounds of the row.
        Rectangle rowBounds = new Rectangle(
            this.dataGridView1.RowHeadersWidth, e.RowBounds.Top,
            this.dataGridView1.Columns.GetColumnsWidth(
                DataGridViewElementStates.Visible) -
            this.dataGridView1.HorizontalScrollingOffset + 1,
            e.RowBounds.Height);

        // Paint the custom selection background.
        using (Brush backbrush =
            new System.Drawing.Drawing2D.LinearGradientBrush(rowBounds,
                this.dataGridView1.DefaultCellStyle.SelectionBackColor,
                e.InheritedRowStyle.ForeColor,
                System.Drawing.Drawing2D.LinearGradientMode.Horizontal))
        {
            e.Graphics.FillRectangle(backbrush, rowBounds);
        }
    }
}

.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:
© 2016 Microsoft