Results 1 to 4 of 4

Thread: [RESOLVED] Question about ListView_ItemSelectionChanged event

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2011
    Posts
    194

    Resolved [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?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Addicted Member
    Join Date
    Jan 2007
    Posts
    199

    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...

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Dec 2011
    Posts
    194

    Re: Question about ListView_ItemSelectionChanged event

    Quote Originally Posted by jmcilhinney View Post
    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
  •  



Click Here to Expand Forum to Full Width