[RESOLVED] Question about ListView_ItemSelectionChanged event
I put some code under the event ListView_ItemSelectionChanged, but unfortunately it is fire two times when i select an item, e.g. the listview contains 1, 2, 3 and 4, if 2 is selected then i select 4, it is fire first with item 2 then with the item 4. I want the code execute for item 4 only, how can i do that?
Re: Question about ListView_ItemSelectionChanged event
The event is raised each time the selection for an item changes and there's nothing you can do about that. When one item is already selected and you select a different item, the event is raised once when the first item is deselected and once when the second item is selected. On the first event the SelectedItems collection will be empty, so that's the condition you should test for.
Re: Question about ListView_ItemSelectionChanged event
Code:
Private Sub lv_main_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lv_main.SelectedIndexChanged
If lv_main.SelectedIndices.Count > 0 Then
messagebox.show (lv_main.SelectedIndices(0))
End If
End Sub
I don't if this help...
Re: Question about ListView_ItemSelectionChanged event
Quote:
Originally Posted by
jmcilhinney
On the first event the SelectedItems collection will be empty, so that's the condition you should test for.
Thanks! that works.