Prova questo codice: -
' Gambas class file
ListView1 As ListView
Label1 As Label
Public Sub Form_Open()
BuildForm
End
Public Sub BuildForm()
Dim sText As String[] = ["Questa", "volta", "mi", "trovo", "a", "voler", "contare", "lo", "faccia"]
Dim iLoop As Integer
With Me
.Arrangement = Arrange.Vertical
.H = 400
.W = 500
.Padding = 5
End With
With ListView1 = New ListView(Me) As "ListView1"
.Expand = True
.ShowCheck = True
.Mode = Select.Multiple
End With
For iLoop = 0 To sText.Max
ListView1.Add(Str(iLoop), sText[iLoop])
Next
With Label1 = New Label(Me) As "Label1"
.H = 28
.W = 100
.Font.Bold = True
.Alignment = Align.Center
End With
End
Public Sub ListView1_Select()
Label1.Text = Str(ListView1.Selection.Count)
End
Giusto, anche questo codice può aiutare a capire:
Private $hList As ListView
Private $hLabel As Label
Public Sub Form_Open()
Dim oPan As HBox
Dim hButton As Button
With Me
.Height = 512
.Width = 512
.Arrangement = Arrange.Vertical
.Margin = True
.Spacing = True
End With
With $hList = New ListView(Me) As "ListView1"
.Expand = True
.Mode = 2 ' multipla
End With
With oPan = New HBox(Me)
.Height = 40
.Spacing = True
End With
With $hLabel = New Label(oPan)
.Expand = True
End With
With hButton = New Button(oPan) As "Button1"
.Text = "Click"
.AutoResize = True
End With
popola
End
Private Sub popola()
' $hList.Add("Pippo", "Pippo")
' $hList.Add("Pluto", "Pluto")
' $hList.Add("Paperino", "Paperino")
' $hList.Add("Gastone", "Gastone")
' $hList.Add("Qui", "Qui")
' $hList.Add("Quo", "Quo")
' $hList.Add("Qua", "Qua")
$hList.Add("1", "Pippo")
$hList.Add("2", "Pluto")
$hList.Add("3", "Paperino")
$hList.Add("4", "Gastone")
$hList.Add("5", "Qui")
$hList.Add("6", "Quo")
$hList.Add("7", "Qua")
End
Public Sub Button1_Click()
Dim s As String
For Each s In $hList.Selection
' $hLabel.text = $hLabel.text & s & " "
$hLabel.text = $hLabel.text & $hList[s].Text & " "
' $hList.Remove(s)
Next
$hList.UnSelectAll
End
:ciao:
Grazie ad entrambi per avermi dato una mano.
Ho usato la soluzione di Cogier, in particolare questa parte:
Label1.Text = Str(ListView1.Selection.Count)
Avevo provato a mischiare Selection e Count in vario modo ma mi mancava anteporre Str() per convertirlo.
La soluzione di Gianluigi l'avevo già utilizzata per inviare il contenuto delle selezioni ad altre funzioni del programma, se ricordo bene proprio suggeritami da lui in un altro post.
A presto.