DataGridViewCell.RowIndex 属性

定义

获取单元格父行的索引。Gets the index of the cell's parent row.

public:
 property int RowIndex { int get(); };
[System.ComponentModel.Browsable(false)]
public int RowIndex { get; }
member this.RowIndex : int
Public ReadOnly Property RowIndex As Integer

属性值

包含该单元格的行的索引;如果无所属行,则为 -1。The index of the row that contains the cell; -1 if there is no owning row.

属性

示例

下面的代码示例演示如何使用此属性。The following code example illustrates the use of this property.

private void getCurrentCellButton_Click(object sender, System.EventArgs e)
{
    string msg = String.Format("Row: {0}, Column: {1}",
        dataGridView1.CurrentCell.RowIndex,
        dataGridView1.CurrentCell.ColumnIndex);
    MessageBox.Show(msg, "Current Cell");
}
Private Sub getCurrentCellButton_Click(ByVal sender As Object, _
    ByVal e As System.EventArgs) Handles getCurrentCellButton.Click

    Dim msg As String = String.Format("Row: {0}, Column: {1}", _
        dataGridView1.CurrentCell.RowIndex, _
        dataGridView1.CurrentCell.ColumnIndex)
    MessageBox.Show(msg, "Current Cell")

End Sub

注解

如果 RowIndex 属性返回-1,则该单元格为列标题,或者该单元格的行是共享的。When the RowIndex property returns -1, the cell is either a column header, or the cell's row is shared.

有关行共享的详细信息,请参阅缩放 Windows 窗体 DataGridView 控件的最佳做法For more information about row sharing, see Best Practices for Scaling the Windows Forms DataGridView Control.

适用于

另请参阅