0

hey suppose I have 3 Rows Items in a ListView.
I want that when i Click on Row1
msgbox comes Yogesh 0

When I click on Row 2
Msgbox Comes Yogesh 1

& SO ON>

But with mine code-
When I click on Row1 msgbox comes Ruchi 0,Ruchi 1, Ruchi 2,
Similarly for all other Rows.

Mine Code is as Under. Plz tell me where I Going Wrong--

Private Sub ListView1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.Click
        Dim lcount As Integer
        For lcount = 0 To ListView1.Items.Count - 1
            MsgBox("Ruchi " & lcount)
        Next
    End Sub
2
Contributors
1
Reply
3
Views
9 Years
Discussion Span
Last Post by KillerOfDN
0

Hi, ruchika beddy.

According to your description of the problem, you simply want a MessageBox to show up, showing Yogesh and the selected ListView item's index... To achieve this, do the following:

Private Sub ListView1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.Click
        MsgBox("Yogesh " & ListView1.FocusedItem.Index.ToString())
    End Sub

The reason you are seeing multiple MessageBox's is because your code is in a loop, and going on the description of what you want, you don't actually need that loop!

Hope this helps

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.