DataGridViewCellFormattingEventArgs.RowIndex 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取正在格式化的单元格的行索引。
public:
property int RowIndex { int get(); };
public int RowIndex { get; }
member this.RowIndex : int
Public ReadOnly Property RowIndex As Integer
属性值
正在格式化的单元格的行索引。
示例
下面的代码示例演示如何使用 RowIndex 属性检索要设置格式的单元格。 然后,使用单元格引用来设置单元格的工具提示文本。
// 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
注解
RowIndex使用 属性获取 的 Rows 属性的DataGridView索引。