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 행에 대해 설정 된 경우 속성.

적용 대상

추가 정보