The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

DataGridViewRowPostPaintEventArgs.RowIndex Property

Gets the index of the current DataGridViewRow.

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

public int RowIndex { get; }

Property Value

Type: System.Int32
The index of the current DataGridViewRow.

The row index can be used to access the current row within a DataGridViewRowCollection.

The following code example demonstrates how to use the RowIndex property to access the current row. The code gets the value of the cell at the intersection of the selected row and the third column, and then paints this value over the entire row. The variable, e, is of type DataGridViewRowPostPaintEventArgs. This code example is part of a larger example provided in How to: Customize the Appearance of Rows in the Windows Forms DataGridView Control.

// Get the content that spans multiple columns. 
object recipe =

if (recipe != null)
    String text = 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.
    Rectangle textArea = rowBounds;
    textArea.X -= this.dataGridView1.HorizontalScrollingOffset;
    textArea.Width += this.dataGridView1.HorizontalScrollingOffset;
    textArea.Y += rowBounds.Height - e.InheritedRowStyle.Padding.Bottom;
    textArea.Height -= rowBounds.Height -
    textArea.Height = (textArea.Height / e.InheritedRowStyle.Font.Height) *

    // Calculate the portion of the text area that needs painting.
    RectangleF clip = textArea;
    clip.Width -= this.dataGridView1.RowHeadersWidth + 1 - clip.X;
    clip.X = this.dataGridView1.RowHeadersWidth + 1;
    RectangleF oldClip = e.Graphics.ClipBounds;

    // Draw the content that spans multiple columns.
        text, e.InheritedRowStyle.Font, forebrush, textArea);


.NET Framework

Supported in: 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.

© 2014 Microsoft