Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select an item ( maybe item row ) in a listview in vb6?

Tags:

listview

vb6

How do I select an item (maybe item row) in a listview in vb6?
I mean, is there any code to do something like programmatically clicking an item at runtime?

somebody told me this :

listview.ListItems(1).Selected = True
listview.select()

but it is not working!

like image 366
OMiD Avatar asked Feb 24 '23 23:02

OMiD


2 Answers

Simply set the .SelectedItem property:

Set ListView.SelectedItem = ListView.ListItems(3)

Also be careful as the listview can have separate "selected" and "highlighted" items. .SelectedItem sets the highlighted item and selects it at the same time. Item.Selected just selectes it, but when reading them back they may be different.

like image 197
Deanna Avatar answered Mar 06 '23 21:03

Deanna


Private Sub Command1_Click()
    ListView1.MultiSelect = True
    For a = 1 To 10
    Randomize Time
    ListView1.ListItems.Item(a).Selected = True
    Next
    ListView1.SetFocus
End Sub

Private Sub Form_Load()
    For a = 1 To 20
    ListView1.ListItems.Add , , a
    Next
End Sub

Do not forget to set HideSelection property to False.

like image 25
OMiD Avatar answered Mar 06 '23 22:03

OMiD