DataGridViewCellFormattingEventArgs.RowIndex Właściwość
Definicja
Ważne
Niektóre informacje odnoszą się do produktu w wersji wstępnej, który może zostać znacząco zmodyfikowany przed wydaniem. Firma Microsoft nie udziela żadnych gwarancji, jawnych lub domniemanych, w odniesieniu do informacji podanych w tym miejscu.
Pobiera indeks wierszy komórki, która jest sformatowana.
public:
property int RowIndex { int get(); };
public int RowIndex { get; }
member this.RowIndex : int
Public ReadOnly Property RowIndex As Integer
Wartość właściwości
Indeks wiersza komórki, która jest sformatowana.
Przykłady
W poniższym przykładzie kodu pokazano, jak za pomocą RowIndex właściwości pobrać sformatowaną komórkę. Odwołanie do komórki jest następnie używane do ustawiania tekstu etykietki narzędzia komórki.
// 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
Uwagi
RowIndex Użyj właściwości , aby uzyskać indeks we Rows właściwości .DataGridView