DataGridViewRowContextMenuStripNeededEventArgs.RowIndex 속성

정의

바로 가기 메뉴를 요청하는 행의 인덱스입니다.

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

속성 값

바로 가기 메뉴를 요청하는 행의 인덱스(0부터 시작)입니다.

예제

다음 코드 예제에서는 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

설명

행에 대한 추가 정보를 검색하려면 이 속성을 사용합니다.

적용 대상

추가 정보