retriving listview subitem values

archer_coal

Well-known member
Joined
Apr 4, 2003
Messages
96
I have a listview with 2 columns
column1 is Item column2 is subitem
there are only 1 subitem per item
i was wondering if there was a way to get the subitem text value from column2 when double clicking Item in column 1

here is what i tried with no luck
Code:
Private Sub ListView1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.DoubleClick
     
Dim i as integer
Dim str as String
str = ListView1.SelectedItems(i).SubItems(i).Text

lblStr.Text = str

End Sub

The above code retrieves the text in the Items column for some reason and not the Subitem
any help?
 
Code:
    Private Sub ListView1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.DoubleClick
        MsgBox(ListView1.SelectedItems(0).SubItems(1).Text)
        /// 1 represents the first subitem ( column 2 )

        MsgBox(ListView1.SelectedItems(0).SubItems(2).Text)
        /// 2 represents the second subitem ( column 3 )
    End Sub
 
maybe youll find an error, so teh best thing will be to do it like this

[VB]
Dim sClient As String = LvProject.SelectedItems.Item( LvProject.Items(0).Index).SubItems(2).Text
[/VB]

I found that sometimes using the zero after SelectedItems returned me wrong values, but with this the correct values where there

regards
 
Back
Top