how to perform click on listview?
when button is click listview will perform a click on first record of a listview

Recommended Answers

All 2 Replies

If you define ListView1 in details view with one column, and one button named Button1 then run this

Public Class Form1

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

        ListView1.Items.Add(New ListViewItem({"the"}))
        ListView1.Items.Add(New ListViewItem({"quick"}))
        ListView1.Items.Add(New ListViewItem({"brown"}))
        ListView1.Items.Add(New ListViewItem({"fox"}))

    End Sub

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        ListView1.SelectedItems.Clear()
        ListView1.Items(0).Selected = True
    End Sub

    Private Sub ListView1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ListView1.SelectedIndexChanged
        If ListView1.SelectedItems.Count > 0 Then
            MsgBox(ListView1.SelectedItems(0).Text)
        End If
    End Sub

End Class

Then clicking the button will select the first item. Note that by first clearing the selected items, every time the button is clicked the SelectedIndexChanged event will trigger.

If you define ListView1 in details view with one column

Do you mean in Designer view? Then in Columns property, add one column? I did that but when I chick the button the selected item does not get highlighted like it does when you just click the item. And the text in the MsgBox is empty.

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.