How to check for selected row in ListView

Bilalq

Member
Joined
Jul 21, 2004
Messages
24
Programming Experience
3-5
Hello,
Can anyone tell me how I can check which row was clicked in a listview control. I am trying to read in subitems in row, but can't seem to read it in for a particular row. I can loop through the entire control and check for a subitem value, but can't do it for the row that was clicked. Here is the code that is I use to loop through the listview control.

VB.NET:
 For i = 0 To lvCards.Items.Count - 1
            If lvCards.Items(i).SubItems(6).Text() = "Y" Then
                blnDefaultCheck = True
                Exit For
            Else
                blnDefaultCheck = False
            End If
        Next

I am looking to see, if there is a way to check for selected row when the user clicks or double clicks a row in a listview control. Thanks for your help
 
Instead of items, use selecteditems. That way you'll only loop through the items that have been selected instead of all of them.

TPM
 
Thank you for your reply, but that still does not give me what row was selected and that is what I am after. Thanks for your help.
 
Thanks for your help TPM. I just figured it out. If any one is interested, here is how you will find out the row selected in a listview control

VB.NET:
j = lvCards.SelectedItems(0).Index

where selecteditem(0) represents the first column (everything else in that row is a subitem for that selecteditem).
 
That'll always give you the index of the first selected item, so if you select more than one item it may not work.
 
True and that what I was interested in. To do miultiple selection you can use SelectedIndices property. Thanks for your help.
 
Bilalg,

Would you please take a look at my post above(Dropdownlistbox runtime selection) and see if you could help me shed a light on it. You know more about it than I do.

I thank you in advance.

dominico
 
Back
Top