Click here to Skip to main content
14,922,560 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to get selected item index number in listview?????????????
Updated 30-Jun-10 6:59am
Abhinav S 30-Jun-10 12:48pm
Sorry - your question does not provide enough information to provide you with a suitable answer.

You really need to start doing your own research. If you want to know what properties, methods, events, etc... that a class has, I would suggest doing a google search. Here is the page for the ListView Members:
ListView Members[^]

I suggest looking through that...maybe for a property that starts with Selected.
You can also use checkboxes in front of your listrows for this.
Set the listview property 'CheckBoxes' to 'True'.

Now you can check the state of an item like so:
Dim v As Integer
   For v = 0 To ListView1.Items.Count - 1
      If ListView1.Items(v).Checked = True Then
         'Do whatever you want to do
      End If
   Next v
William Winner 1-Jul-10 12:49pm
well that's a roundabout way of getting the selected index for a ListView...especially considering you could just do:

For i = 0 To listView1.SelectedIndices.Count - 1
'do something with each selected index


For i = 0 To listView1.CheckedIndices.Count - 1
'Do something with each checked index

What if you had 1500 items in your ListView (which some people are determined to do) and two items selected or checked?

Then, instead of just getting the two selected/checked items, you want him to search through all 1500 items to find the two that are selected/checked?
Scubapro 2-Jul-10 1:48am
Your right, ofcourse. But some people find checkboxes more aesthetically pleasing.

Hey, not everyone is a "winner".
selecteditems(i).count should tell you how many items have been selected if you allow multiple selects,

otherwise use selecteditems(0).item for just one item.
tiggerc 1-Jul-10 8:34am
I use selecteditems which is an array of the items selected, its a little quirky but i find it normal now, makes handling multiple selects easy
but in listview property not available selectedIndex............
William Winner 30-Jun-10 13:33pm
Reason for my vote of 1
again, don't post a new "answer". add a comment to the previous answer.

And, no it doesn't have SelectedIndex. But didn't you notice something very similar? Do you know what the plural of index is?

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