DataGridViewCellFormattingEventArgs.RowIndex Eigenschaft

Definition

Ruft den Zeilenindex der Zelle ab, die formatiert wird.

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

Eigenschaftswert

Der Zeilenindex der Zelle, die formatiert wird.

Beispiele

Im folgenden Codebeispiel wird veranschaulicht, wie die RowIndex -Eigenschaft verwendet wird, um die zelle abzurufen, die formatiert wird. Der Zellverweis wird dann verwendet, um den QuickInfo-Text der Zelle festzulegen.

// Sets the ToolTip text for cells in the Rating column.
void dataGridView1_CellFormatting(Object^ /*sender*/, 
    DataGridViewCellFormattingEventArgs^ e)
{
    if ( (e->ColumnIndex == this->dataGridView1->Columns["Rating"]->Index)
        && e->Value != nullptr )
    {
        DataGridViewCell^ cell = 
            this->dataGridView1->Rows[e->RowIndex]->Cells[e->ColumnIndex];
        if (e->Value->Equals("*"))
        {                
            cell->ToolTipText = "very bad";
        }
        else if (e->Value->Equals("**"))
        {
            cell->ToolTipText = "bad";
        }
        else if (e->Value->Equals("***"))
        {
            cell->ToolTipText = "good";
        }
        else if (e->Value->Equals("****"))
        {
            cell->ToolTipText = "very good";
        }
    }
}
// Sets the ToolTip text for cells in the Rating column.
void dataGridView1_CellFormatting(object sender, 
    DataGridViewCellFormattingEventArgs e)
{
    if ( (e.ColumnIndex == this.dataGridView1.Columns["Rating"].Index)
        && e.Value != null )
    {
        DataGridViewCell cell = 
            this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];
        if (e.Value.Equals("*"))
        {                
            cell.ToolTipText = "very bad";
        }
        else if (e.Value.Equals("**"))
        {
            cell.ToolTipText = "bad";
        }
        else if (e.Value.Equals("***"))
        {
            cell.ToolTipText = "good";
        }
        else if (e.Value.Equals("****"))
        {
            cell.ToolTipText = "very good";
        }
    }
}
' Sets the ToolTip text for cells in the Rating column.
Sub dataGridView1_CellFormatting(ByVal sender As Object, _
    ByVal e As DataGridViewCellFormattingEventArgs) _
    Handles dataGridView1.CellFormatting

    If e.ColumnIndex = Me.dataGridView1.Columns("Rating").Index _
        AndAlso (e.Value IsNot Nothing) Then

        With Me.dataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex)

            If e.Value.Equals("*") Then
                .ToolTipText = "very bad"
            ElseIf e.Value.Equals("**") Then
                .ToolTipText = "bad"
            ElseIf e.Value.Equals("***") Then
                .ToolTipText = "good"
            ElseIf e.Value.Equals("****") Then
                .ToolTipText = "very good"
            End If

        End With

    End If

End Sub

Hinweise

Verwenden Sie die RowIndex -Eigenschaft, um einen Index in die Rows -Eigenschaft eines DataGridViewabzurufen.

Gilt für:

Weitere Informationen