Results 1 to 3 of 3

Thread: [2005] Listbox Issue

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2003
    Location
    Auckland
    Posts
    1,139

    [2005] Listbox Issue

    I have this code and when I click the listbox2 and run the debug it hits Listbox1.ClearSelected() then runs code block 2.... why? and how can I stop it?

    (Yes i've tried MSDN)

    Code #1
    Code:
    Private Sub ListBox2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox2.SelectedIndexChanged
    
    ListBox1.ClearSelected()
    ..
    ..
    ..
    Code Block #2
    Code:
    Private Sub ListBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
            ListBox2.ClearSelected()
    
            Dim ssfolder As String
            ssfolder = ListBox1.SelectedItem

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

    Re: [2005] Listbox Issue

    Your methods are named as though they are handling a Click event yet they are handling a SelectedIndexChanged event. You should use more appropriate method names.

    You are handling the SelectedIndexChanged event. If an item is selected and you clear it then that's going to change the SelectedIndex and rasie the SelectedIndexChanged event. If you don't want to clear the other ListBox when this ListBox is cleared then you have to test for that state. What condition would indicate that no item was selected in the ListBox? You need to test for that condition and only clear the other selection if it's False.
    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
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    Re: [2005] Listbox Issue

    Possibly because it is firing ListBox1's Click Event when it does the ClearSelect.

    Maybe you can set a Boolean Flag that gets set in ListBox2, and when ListBox1's Click Event is fired as a result of ListBox2's clear, ignore it. That will enable normal Clicking. Of course you would apply the same to ListBox2.
    Alternatly, there may be other Events you can use in this instance.

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