DataGridViewCell.RowIndex プロパティ

定義

セルの親行のインデックスを取得します。

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

プロパティ値

セルが格納されている行のインデックス。セルを所有している行がない場合は -1。

属性

次のコード例は、このプロパティの使用方法を示しています。

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 を返す場合、セルは列ヘッダーであるか、セルの行が共有されます。

行の共有の詳細については、「Windows フォーム DataGridView コントロールを拡張するための推奨される手順」を参照してください。

適用対象

こちらもご覧ください