DataGridViewRowContextMenuStripNeededEventArgs.ContextMenuStrip DataGridViewRowContextMenuStripNeededEventArgs.ContextMenuStrip DataGridViewRowContextMenuStripNeededEventArgs.ContextMenuStrip DataGridViewRowContextMenuStripNeededEventArgs.ContextMenuStrip Property

定義

RowContextMenuStripNeeded イベントの発生元である行のショートカット メニューを取得または設定します。Gets or sets the shortcut menu for the row that raised the RowContextMenuStripNeeded event.

public:
 property System::Windows::Forms::ContextMenuStrip ^ ContextMenuStrip { System::Windows::Forms::ContextMenuStrip ^ get(); void set(System::Windows::Forms::ContextMenuStrip ^ value); };
public System.Windows.Forms.ContextMenuStrip ContextMenuStrip { get; set; }
member this.ContextMenuStrip : System.Windows.Forms.ContextMenuStrip with get, set
Public Property ContextMenuStrip As ContextMenuStrip

プロパティ値

次のコード例では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;
    }
    else
    {
        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 = _
    dataGridView1.Rows(e.RowIndex)

    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
    Else
        e.ContextMenuStrip = employeeMenuStrip
    End If

    contextMenuRowIndex = e.RowIndex
End Sub

注釈

このプロパティは、行に対してDataGridViewRow.ContextMenuStrip設定されている場合、最初にプロパティの値を格納します。This property initially contains the value of the DataGridViewRow.ContextMenuStrip property if it has been set for a row.

適用対象

こちらもご覧ください