|
-
May 22nd, 2012, 02:59 PM
#1
Thread Starter
Addicted Member
[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?
-
May 22nd, 2012, 07:03 PM
#2
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.
-
May 22nd, 2012, 10:17 PM
#3
Addicted Member
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...
-
May 23rd, 2012, 09:04 AM
#4
Thread Starter
Addicted Member
Re: Question about ListView_ItemSelectionChanged event
 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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|