|
Steps to reproduce:
Add a listview to a form. Set its "view" property to "Details". Set its "checkboxes" property to "True". Add a column to it.
Put this code in the form load event:
Private Sub Form1_Load... Dim i As Integer For i = 0 To 50 ListView1.Items.Add("Item " & i.ToString) Next End Sub
Put a button on the form. Under the button, add this code:
Private Sub Button1_Click... Dim li As ListViewItem Dim i As Integer Debug.WriteLine("") For Each li In ListView1.CheckedItems Debug.WriteLine(li.Text) Next For i = 0 To ListView1.CheckedIndices.Count - 1 Debug.WriteLine(ListView1.Items(ListView1.CheckedIndices.Item(i)).Text) Next For i = 0 To ListView1.CheckedItems.Count - 1 Debug.WriteLine(ListView1.CheckedItems(i).Text) Next Debug.WriteLine("") End Sub
Now, check "Item 3", then click the button. You will see this in the output window:
Item 3 Item 3 Item 3
Now for the good part... check "Item 4", uncheck "Item 3", and click the button again. Here is what you see in the output window:
Item 4 Item 3 Item 3
Oops....
|