RowIndex Property

DataGridViewCell.RowIndex Property

 

Gets the index of the cell's parent row.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

[BrowsableAttribute(false)]
public int RowIndex { get; }

Property Value

Type: System.Int32

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

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.

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");
}

.NET Framework
Available since 2.0
Return to top
Show:
© 2016 Microsoft