Click here to Skip to main content
15,904,500 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Please someone help me on doing a loop on how to get all the checked items in listview in vb.net

I'm calling this loop when i press a button
but the problem is that i have an error in the beginning of the With listview to End With

VB
Dim i As Integer = 0
Dim rCnt As Integer = ListView1.Columns.Count
For i = 0 To rCnt - 1
    With ListView1
        SaveItem(.Items(1, i).Value, .Items(2, i).Value)
    End With
Next


And here's my SaveItem() Function

VB
Public Sub SaveItem(ByVal strBrchID As String, _
                     ByVal strBrchName As String)
.........
End Sub


[Modified: added pre tags to format code]
Posted
Updated 16-Apr-10 6:42am
v3

1 solution

It looks like you don't understand the ListView.

Your problem is that ListView.Items does not take two parameters. Nor does a ListViewItem have a Value property. It looks like you're mixing VB6 and VB.NET.

To begin with, you said your question title said you needed help with getting CheckedItems. But your code doesn't deal with that at all. Then, there's the problems with your code that I've already said.

If you want to deal with CheckedItems only, the ListView has a CheckedItems collection.

You can simply do:
VB
For Each item As ListViewItem In ListView1.CheckedItems

Next


Then, to access different columns, you want to access the SubItems of each item. But remember that the first column is SubItem(0). If you want what is displayed, you want
VB
item.SubItem(0).Text

There are other properties that can be very useful to set with a ListViewItem such as the Tag property which can be any Object or the Name property.

First, though, actually look at the ListView class next time and the ListViewItem class to see how to use them.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900