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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.