[RESOLVED] How can I pass a name selected from a ListView into another form
Hi,
I have a form when, in a ListView, I select a name. How can I pass this name into another form as a parameter or something else.
So let's say that in form1 I select a name from a ListView and I want to open form2 that know the name selected in form1.
Thank you
Robert
Re: How can I pass a name selected from a ListView into another form
You could either create a constructor that takes the parameters you wish to pass, or create a public property that you set after creating the form.
The constructor option would look like this:
Code:
Public Class MyForm
Private someText as String
Sub New(ByVal text As String)
Me.someText = text
End Sub
End Class
And the usage is simple
Code:
Dim instance As New MyForm("Hello world")
Re: How can I pass a name selected from a ListView into another form
You could always create a module, and store it away as a pubic variable
Re: How can I pass a name selected from a ListView into another form
I tried to store the selected item from listview into a public variable named "selection" in form1, and I tried to display the content of "selection" variable in form2.
Unfortunatelly I receive an error message "NullReference" so, I think that the content of "selection" variable is lost somwhere between form1 and form2.
Re: How can I pass a name selected from a ListView into another form
Quote:
Originally Posted by
petevick
You could always create a module, and store it away as a pubic variable
Please, you can be more specific? What means to create a module?
Thank you
Re: How can I pass a name selected from a ListView into another form
How are you trying to access that public variable in Form1?
Have you tried the constructor solution I mentioned?
Re: How can I pass a name selected from a ListView into another form
Quote:
Originally Posted by
Atheist
How are you trying to access that public variable in Form1?
In Form1 I have the ListView and a procedure like this:
Code:
Public Sub take()
Form2.selection = ListView1.FocusedItem.Text
End Sub
and in Form2 I have:
and
Code:
Me.Label1.Text = selection
Re: How can I pass a name selected from a ListView into another form
I bet this problem origins from the use of default instances. Where is the NullReferenceException being thrown? My guess is that you're calling the 'take' method on the default instance, and the actual Form1 you're displaying is not the default instance.
I still think the constructor solution is the best design in this case though.
Re: How can I pass a name selected from a ListView into another form
Project>Add Module
Public strCustomer
then on selection of the listview
strCustomer = listview1(isel).text
Re: [RESOLVED] How can I pass a name selected from a ListView into another form