DataGridViewRowContextMenuStripNeededEventArgs.RowIndex Propiedad

Definición

Obtiene el índice de la fila que está solicitando un menú contextual.Gets the index of the row that is requesting a shortcut menu.

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

Valor de propiedad

Índice de base cero de la fila que está solicitando un menú contextual.The zero-based index of the row that is requesting a shortcut menu.

Ejemplos

En el ejemplo de código siguiente RowContextMenuStripNeeded se controla el evento ContextMenuStrip para proporcionar un basado en el título del empleado.The following code example handles the RowContextMenuStripNeeded event to provide a ContextMenuStrip based on the title of the employee. En este ejemplo, hay dos menús contextuales, uno para los administradores y otro para los demás empleados.In this example, there are two shortcut menus, one for managers and one for all other employees. Este ejemplo forma parte de un ejemplo más grande disponible en DataGridViewRowContextMenuStripNeededEventArgs la información general de la clase.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

Comentarios

Utilice esta propiedad para recuperar información adicional sobre la fila.Use this property to retrieve additional information about the row.

Se aplica a

Consulte también: