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
Printable View
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
Try adding code to the DoubleClick event?
And use the listbox's selected item property to retrieve the value to pass to the form you want to open.
Expand on the problem a little more if you want more advice :)
can post some examples on doing it....
I am confuse...
Thanks
Before I do, are the items in your listbox just strings?
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
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..
The above code cannot works....it give an error: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
ThanksCode:Additional information: Object reference not set to an instance of an object.
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 :D
thanks....
but both your methods cannot work..
it still give the same error..
I hate to sound pedantic but have you copied and pasted the code into your project? They both work in the project I have here so maybe we are at cross purposes somewhere :confused: : :confused:
Post back what you NOW have in your form and I'll take another look :)
ooh.....it is my error..
it works...
I left out some coding after i double check it...
:sick:
thanks