다음을 통해 공유


DataGridViewRowContextMenuStripNeededEventArgs.ContextMenuStrip 속성

정의

이벤트를 발생 RowContextMenuStripNeeded 시킨 행의 바로 가기 메뉴를 가져오거나 설정합니다.

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

속성 값

ContextMenuStrip 사용 중인 것입니다.

예제

다음 코드 예제에서는 RowContextMenuStripNeeded 직원의 제목에 따라 제공 ContextMenuStrip 하는 이벤트를 처리 합니다. 이 예제에는 두 개의 바로 가기 메뉴가 있습니다. 하나는 관리자용이고 다른 모든 직원은 바로 가기 메뉴입니다. 이 예제는 클래스 개요에서 사용할 수 있는 더 큰 예제의 DataGridViewRowContextMenuStripNeededEventArgs 일부입니다.

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 값을 처음에 포함합니다.

적용 대상

추가 정보