DataGridViewRowContextMenuStripNeededEventArgs.RowIndex DataGridViewRowContextMenuStripNeededEventArgs.RowIndex DataGridViewRowContextMenuStripNeededEventArgs.RowIndex DataGridViewRowContextMenuStripNeededEventArgs.RowIndex Property


ショートカット メニューを要求している行のインデックスを取得します。Gets the index of the row that is requesting a shortcut menu.

 property int RowIndex { int get(); };
public int RowIndex { get; }
member this.RowIndex : int
Public ReadOnly Property RowIndex As Integer


ショートカット メニューを要求している行の 0 から始まるインデックス。The zero-based index of the row that is requesting a shortcut menu.

次のコード例ではRowContextMenuStripNeeded 、イベントを処理ContextMenuStripして、従業員のタイトルに基づいてを提供します。The following code example handles the RowContextMenuStripNeeded event to provide a ContextMenuStrip based on the title of the employee. この例では、2つのショートカットメニューがあります。1つはマネージャー用で、もう1つは他のすべての従業員用です。In this example, there are two shortcut menus, one for managers and one for all other employees. この例は、 DataGridViewRowContextMenuStripNeededEventArgsクラスの概要で使用できるより大きな例の一部です。This example is part of a larger example available in the DataGridViewRowContextMenuStripNeededEventArgs class overview.

void dataGridView1_RowContextMenuStripNeeded(object sender,
    DataGridViewRowContextMenuStripNeededEventArgs e)
    DataGridViewRow dataGridViewRow1 = dataGridView1.Rows[e.RowIndex];

    toolStripMenuItem1.Enabled = true;

    // Show the appropriate ContextMenuStrip based on the employees title.
    if ((dataGridViewRow1.Cells["Title"].Value.ToString() ==
        "Sales Manager") ||
        (dataGridViewRow1.Cells["Title"].Value.ToString() ==
        "Vice President, Sales"))
        e.ContextMenuStrip = managerMenuStrip;
        e.ContextMenuStrip = employeeMenuStrip;

    contextMenuRowIndex = e.RowIndex;
Public Sub dataGridView1_RowContextMenuStripNeeded( _
    ByVal sender As Object, _
    ByVal e As DataGridViewRowContextMenuStripNeededEventArgs) _
    Handles dataGridView1.RowContextMenuStripNeeded

    Dim dataGridViewRow1 As DataGridViewRow = _

    toolStripMenuItem1.Enabled = True

    ' Show the appropriate ContextMenuStrip based on the employees title.
    If dataGridViewRow1.Cells("Title").Value.ToString() = _
        "Sales Manager" OrElse _
        dataGridViewRow1.Cells("Title").Value.ToString() = _
        "Vice President, Sales" Then

        e.ContextMenuStrip = managerMenuStrip
        e.ContextMenuStrip = employeeMenuStrip
    End If

    contextMenuRowIndex = e.RowIndex
End Sub


このプロパティを使用して、行に関する追加情報を取得します。Use this property to retrieve additional information about the row.