DataGridViewRowPostPaintEventArgs.RowIndex DataGridViewRowPostPaintEventArgs.RowIndex DataGridViewRowPostPaintEventArgs.RowIndex DataGridViewRowPostPaintEventArgs.RowIndex Property

定義

現在の DataGridViewRow のインデックスを取得します。Gets the index of the current DataGridViewRow.

public:
 property int RowIndex { int get(); };
public int RowIndex { get; }
member this.RowIndex : int
Public ReadOnly Property RowIndex As Integer

プロパティ値

現在の DataGridViewRow のインデックス。The index of the current DataGridViewRow.

次のコード例は、 RowIndexプロパティを使用して現在の行にアクセスする方法を示しています。The following code example demonstrates how to use the RowIndex property to access the current row. このコードは、選択された行と3番目の列の交差部分にあるセルの値を取得し、この値を行全体に対して描画します。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. 変数eの型DataGridViewRowPostPaintEventArgsはです。The variable, e, is of type DataGridViewRowPostPaintEventArgs. このコード例は、次の方法で提供される大規模な例の一部です。Windows フォーム DataGridView コントロールの行の外観をカスタマイズします。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 =
    this.dataGridView1.Rows.SharedRow(e.RowIndex).Cells[2].Value;

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 -
        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.
    RectangleF clip = textArea;
    clip.Width -= this.dataGridView1.RowHeadersWidth + 1 - clip.X;
    clip.X = this.dataGridView1.RowHeadersWidth + 1;
    RectangleF oldClip = 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);
}
' 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

注釈

行インデックスを使用して、 DataGridViewRowCollection内の現在の行にアクセスできます。The row index can be used to access the current row within a DataGridViewRowCollection.

適用対象

こちらもご覧ください