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; }
[<System.ComponentModel.Browsable(false)>]
member this.RowIndex : int
Public ReadOnly Property RowIndex As Integer

屬性值

Int32

包含儲存格之資料列的索引,如果沒有主控資料列,則為 -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 Forms DataGridView 控制項的最佳做法For more information about row sharing, see Best Practices for Scaling the Windows Forms DataGridView Control.

適用於

另請參閱