DataGridViewCell.RowIndex DataGridViewCell.RowIndex DataGridViewCell.RowIndex DataGridViewCell.RowIndex Property

Definition

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

Property Value

The index of the row that contains the cell; -1 if there is no owning row.

Examples

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

Remarks

When the RowIndex property returns -1, the cell is either a column header, or the cell's row is shared.

For more information about row sharing, see Best Practices for Scaling the Windows Forms DataGridView Control.

Applies to

See also