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 Forms DataGridView 控件的最佳做法

適用於

另請參閱