DataGridViewRowPrePaintEventArgs.RowIndex 속성

정의

현재 DataGridViewRow의 인덱스를 가져옵니다.

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

속성 값

Int32

현재 DataGridViewRow의 인덱스입니다.

예제

다음 코드 예제에서는 현재 행에 RowIndex 액세스 하는 속성을 사용 하는 방법을 보여 줍니다. 코드에서 실제로 속성을 사용 DataGridViewRowPostPaintEventArgs.RowIndex 하지만 이 속성은 .의 DataGridViewRowPrePaintEventArgs속성과 RowIndex 거의 동일합니다. 변수는 e형식입니다 DataGridViewRowPostPaintEventArgs. 이 코드 예제는에서 제공 하는 더 큰 예제의 일부입니다 방법: Windows Forms DataGridView 컨트롤에서 행 모양 사용자 지정합니다.

// 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.

적용 대상

추가 정보