[RESOLVED] List Box and Mouse Click Event While missing Selected item
Ok, I have a listbox that has a double click event on it. If you strike the items in the list the program works perfectly without a problem, but if you hit white space, the program blows up.
The frmOpen has a rich text box that uses the data from transfername on it to call forth a name from another system.
The question I have, Is there a way to show the system that there is nothing being clicked? I have tried the selecteditem = 0 and -1 and the selectedindex = 0 and -1 nothing happened. I'm kind of lost on this one. Trying to make this work for my new job.
Code:
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.MouseDoubleClick
Dim transfername As String = ListBox1.SelectedItem.ToString()
frmOpen.Show()
frmOpen.filename = transfername
End Sub
VB.net 2010 Professional Edition.
Re: List Box and Mouse Click Event While missing Selected item
If no item is selected then what's the value of SelectedItem? Have you actually checked that? What is usually used in VB to represent no object?
Re: List Box and Mouse Click Event While missing Selected item
It's referenced as a null object. How do I make a test for that null object with a list box? I'm not to sure how to do that.
Never Mind, I found a try catch. :D Thanks for the help.
Re: List Box and Mouse Click Event While missing Selected item
Quote:
Originally Posted by
davebold370
It's referenced as a null object. How do I make a test for that null object with a list box? I'm not to sure how to do that.
Never Mind, I found a try catch. :D Thanks for the help.
NOOOOOOOOOO!!! That is a terrible solution. No object in VB is Nothing. All you have to do is test whether the SelectedItem Is Nothing.
Re: [RESOLVED] List Box and Mouse Click Event While missing Selected item
Re: [RESOLVED] List Box and Mouse Click Event While missing Selected item
I'm looking back at my posts and I'm struggling to find where I said that you should compare the SelectedItem to an empty String. I said Nothing and I meant Nothing. You need to do exactly what I said to do:
Quote:
All you have to do is test whether the SelectedItem Is Nothing.