DataGridViewRowContextMenuStripNeededEventArgs.ContextMenuStrip Właściwość

Definicja

Pobiera lub ustawia menu skrótów dla wiersza, który wzbudził RowContextMenuStripNeeded zdarzenie.

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; }
public System.Windows.Forms.ContextMenuStrip? ContextMenuStrip { get; set; }
member this.ContextMenuStrip : System.Windows.Forms.ContextMenuStrip with get, set
Public Property ContextMenuStrip As ContextMenuStrip

Wartość właściwości

Element ContextMenuStrip w użyciu.

Przykłady

Poniższy przykład kodu obsługuje RowContextMenuStripNeeded zdarzenie, aby podać element ContextMenuStrip na podstawie tytułu pracownika. W tym przykładzie istnieją dwa menu skrótów, jedno dla menedżerów i jeden dla wszystkich innych pracowników. Ten przykład jest częścią większego przykładu dostępnego w przeglądzie DataGridViewRowContextMenuStripNeededEventArgs klasy.

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

Uwagi

Ta właściwość początkowo zawiera wartość DataGridViewRow.ContextMenuStrip właściwości, jeśli została ustawiona dla wiersza.

Dotyczy

Zobacz też