|
-
Jun 15th, 2013, 11:22 PM
#1
Thread Starter
Junior Member
[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.
Last edited by davebold370; Jun 15th, 2013 at 11:28 PM.
-
Jun 15th, 2013, 11:33 PM
#2
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?
-
Jun 15th, 2013, 11:38 PM
#3
Thread Starter
Junior Member
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. Thanks for the help.
-
Jun 15th, 2013, 11:43 PM
#4
Re: List Box and Mouse Click Event While missing Selected item
 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.  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.
-
Jun 15th, 2013, 11:45 PM
#5
Thread Starter
Junior Member
Re: [RESOLVED] List Box and Mouse Click Event While missing Selected item
-
Jun 16th, 2013, 12:07 AM
#6
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:
All you have to do is test whether the SelectedItem Is Nothing.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|