45 pts.
 vb.net listbox problem
vb.net related questoin. i have 3 items in listbox. At one of list item i have applide method that on selectedvaluechanged open a combobox but when i click on the blank space in listbox other than listbox items, the combobox appeared still. means the selectedvaluechanged is called again. how to stop this functon call when i click the blank space?

Software/Hardware used:
visual studio 2005
ASKED: October 28, 2009  5:50 AM
UPDATED: October 30, 2009  2:25 PM

Answer Wiki:
I gave it a try, and in fact both handlers SelectedIndexChanged and SelectedValueChanged fire when you click inside the list box, even when the selected item has not changed or when you click on an empty position, and I didn't find a way to change that behavior. When in MultiSimple selection mode it works a little different, and I think you could write some code to limit the selected items number, but it would be more complex. One workaround would be using a variable to store the previous selected item index, and ignoring the event when the selected index is the same as the previous selection (when you click on an empty position, the event fires, but the selection doesn't change). Something like this: <pre> Private Sub ListBox1_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedValueChanged If mySelectedIndex <> ListBox1.SelectedIndex Then ' do what you have to do mySelectedIndex = ListBox1.SelectedIndex End If End Sub</pre> ---------------- Thank u CARLOSDL i have found the way how to solve my problem. this problem can be handled by doing so <pre>Private Sub ListBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox1.SelectedIndexChanged If (ListBox1.IndexFromPoint(e.X, e.Y) = ListBox.NoMatches) Then ListBox1.SetSelected(0, False) Else If ListBox1.SelectedIndex = 0 Then // do here what you want Else // do here what you want End If End If End Sub </pre>
Last Wiki Answer Submitted:  October 30, 2009  2:25 pm  by  carlosdl   63,535 pts.
All Answer Wiki Contributors:  carlosdl   63,535 pts. , Vbnet12322   45 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _