How d开发者_C百科o 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!
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.
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
.
ListView1_ItemClick ListView1.ListItems.item(1)
精彩评论