[SOLUCIONADO] Problema con multi-selección en listview
(1/1)
Eleкtro:
El problema es que selecciono varias líneas, abro un menú contextual, hago click en la opción deseada pero el contenido de la variable "FileInformation" siempre es el mismo valor, si selecciono 5 líneas pues el valor es siempre el de la primera línea...
¿Estoy usando mal el índice?
EDITO: se me olvidaba comentar que se trata de un listview con 2 columnas y yo intento mostrar el item de la segunda columna. La opción de seleccionar la "row" entera está activada.
Código
Private Sub NewMenu_ItemClicked(sender As Object, e As ToolStripItemClickedEventArgs) Handles NewMenu.ItemClicked
Dim FileInformation = Nothing
If e.ClickedItem.Name = "OpenDir" Then
For Each Entry In ListView1.SelectedItems()
FileInformation = My.Computer.FileSystem.GetFileInfo(ListView1.SelectedItems(0).SubItems(1).Text)
MsgBox("explorer.exe" & " /select," & FileInformation.DirectoryName & "\" & FileInformation.Name)
'Process.Start("explorer.exe", " /select," & FileInformation.DirectoryName & "\" & FileInformation.Name)
FileInformation = Nothing
Next
End If
En cambio esto me funciona perféctamente:
Código
If e.ClickedItem.Name = "DeleteEntry" Then
For Each Entry In ListView1.SelectedItems()
ListView1.Items.Remove(ListView1.SelectedItems(0))
Next
End If
Eleкtro:
kawen, ¿Nadie tiene una respuesta para este problema? :(
HdM:
Hola.
Citar
¿Estoy usando mal el índice?
Código
FileInformation = My.Computer.FileSystem.GetFileInfo(ListView1.SelectedItems(0).SubItems(1).Text
Efectivamente, siempre estás seleccionando el 1er item (SelectedItems(0)).
Prueba sustituyendo esa línea por:
Código
FileInformation = My.Computer.FileSystem.GetFileInfo(ListView1.Items(entry.Index).SubItems(1).Text)
Un saludo.
Eleкtro:
Gracias HdM ;D.
Navegación