vb.net listbox problem
45 pts.
0
Q:
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: Oct 28 2009  5:50 AM GMT
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
0
29805 pts.
0
A:
 RATE THIS ANSWER
+1
Click to Vote:
  •   1
  •  0
  • AddThis Social Bookmark Button
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:

    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


----------------

Thank u CARLOSDL
i have found the way how to solve my problem.


this problem can be handled by doing so


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
Last Answered: Oct 30 2009  2:25 PM GMT by Carlosdl   29805 pts.
Latest Contributors: Vbnet12322   45 pts.
0
0
Discuss This Answer:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _



_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

Vbnet12322   45 pts.  |   Oct 30 2009  3:42AM GMT

thanndkk skdfjlkjsdf sdfkjdf aljklsdfjjaisdf isadfjlasdjfissa ls dfi

 
0