Trucos Seleccionar una fila de un ListView con el botón derecho

Si queremos, por ejemplo, que al pinchar sobre una fila de un listview con el botón derecho del ratón se seleccione la fila completa y aparezca un menú contextual podremos hacer :

Private Sub ListView1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim elemento As ListItem
If Button = 2 Then
    Set elemento = ListView1.HitTest(x, y)
    If Not elemento Is Nothing Then
        Set ListView1.SelectedItem = elemento
        PopupMenu mnuPopUp
    End If
    Set elemento = Nothing
End If
End Sub

En este ejemplo suponemos que existe un menú llamado mnuPopUp y que la propiedad FullRowSelect del ListView está a true.



Trucos Trucos

Visual Basic Página de Visual Basic

Página principal Página principal

www.jrubi.com