|
-
Nov 24th, 2004, 05:05 AM
#1
Thread Starter
Addicted Member
VB.NET: Trigger Event inside Listbox....[Resolved]
Does anyone know how to trigger the event inside the listbox when i double click on it....
Say when i double click on one of the items, it will bring me to another form...
Thanks
Last edited by toytoy; Nov 24th, 2004 at 10:07 AM.
-
Nov 24th, 2004, 05:30 AM
#2
-
Nov 24th, 2004, 05:54 AM
#3
Thread Starter
Addicted Member
can post some examples on doing it....
I am confuse...
Thanks
-
Nov 24th, 2004, 06:02 AM
#4
Hyperactive Member
Before I do, are the items in your listbox just strings?
Be who you are and say what you feel, because those who mind don't matter and those who matter don't mind.
Dr. Seuss 
-
Nov 24th, 2004, 06:24 AM
#5
Hyperactive Member
Okay, this example assumes you have a list box containing five customers. It also assumes you have a customer form with a public variable called CustomerID.
VB Code:
Private Sub ListBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick
Dim customerForm As New frmCustomer
Select Case ListBox1.SelectedItem.ToString
Case "Customer 1"
customerForm.CustomerID = 1
Case "Customer 2"
customerForm.CustomerID = 2
Case "Customer 3"
customerForm.CustomerID = 3
Case "Customer 4"
customerForm.CustomerID = 4
Case "Customer 5"
customerForm.CustomerID = 5
End Select
customerForm.Show()
End Sub
Be who you are and say what you feel, because those who mind don't matter and those who matter don't mind.
Dr. Seuss 
-
Nov 24th, 2004, 07:32 AM
#6
Thread Starter
Addicted Member
Lil Ms Squirrel thanks...it works..
how about if the items is Integer.....how to do it ?..
now i have another problem..
say double click on one of the items in the listbox from Form1, it will bring me to Form2..
but from Form2, how to link back to form1 again...
This is my coding..
Code:
'Inside Form1
Public vForm2 As New Form2
Public vForm3 As New Form3
Private Sub ListBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick
Dim form2 As New Form2
Dim form3 As New Form3
Select Case ListBox1.SelectedItem.ToString
Case "Form2"
form2.Show()
vForm2.Owner = Me
Me.Hide()
Case "Form3"
form3.Show()
vForm3.Owner = Me
Me.Hide()
End Select
End Sub
'Inside Form2
Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label2.Click
Me.Owner.Show()
End Sub
'Inside Form3
Private Sub Label3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label3.Click
Me.Owner.Show()
End Sub
The above code cannot works....it give an error:
Code:
Additional information: Object reference not set to an instance of an object.
Thanks
Last edited by toytoy; Dec 3rd, 2004 at 07:46 AM.
-
Nov 24th, 2004, 08:34 AM
#7
Hyperactive Member
You've gotten your variables a bit mixed up.
Either:
VB Code:
'Inside Form1
Public vForm2 As New Form2
Public vForm3 As New Form3
Private Sub ListBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick
Select Case ListBox1.SelectedItem.ToString
Case "Form2"
vForm2.Show()
vForm2.Owner = Me
Me.Hide()
Case "Form3"
vForm3.Show()
vForm3.Owner = Me
Me.Hide()
End Select
End Sub
Or
VB Code:
'Inside Form1
Private Sub ListBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick
Dim form2 As New Form2
Dim form3 As New Form3
Select Case ListBox1.SelectedItem.ToString
Case "Form2"
form2.Show()
form2 .Owner = Me
Me.Hide()
Case "Form3"
form3.Show()
form3 .Owner = Me
Me.Hide()
End Select
End Sub
You were using a mixture of the two, hence when you asked form2 what it's Owner was, you were referring to a different object than the one you'd set the property for.
Hope this helps
Be who you are and say what you feel, because those who mind don't matter and those who matter don't mind.
Dr. Seuss 
-
Nov 24th, 2004, 09:11 AM
#8
Thread Starter
Addicted Member
thanks....
but both your methods cannot work..
it still give the same error..
-
Nov 24th, 2004, 09:38 AM
#9
Hyperactive Member
-
Nov 24th, 2004, 09:53 AM
#10
Thread Starter
Addicted Member
ooh.....it is my error..
it works...
I left out some coding after i double check it...
thanks
Last edited by toytoy; Nov 24th, 2004 at 10:19 AM.
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
|