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