0

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

3
Contributors
2
Replies
11
Views
3 Years
Discussion Span
Last Post by Ancient Dragon
0

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.

0

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.

Edited by Ancient Dragon

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.