|
-
Jun 15th, 2009, 06:38 AM
#1
Thread Starter
New Member
[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
-
Jun 15th, 2009, 07:40 AM
#2
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")
-
Jun 15th, 2009, 09:12 AM
#3
Frenzied Member
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
-
Jun 16th, 2009, 02:48 AM
#4
Thread Starter
New Member
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.
-
Jun 16th, 2009, 02:50 AM
#5
Thread Starter
New Member
Re: How can I pass a name selected from a ListView into another form
 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
-
Jun 16th, 2009, 04:04 AM
#6
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?
-
Jun 16th, 2009, 04:11 AM
#7
Thread Starter
New Member
Re: How can I pass a name selected from a ListView into another form
 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
-
Jun 16th, 2009, 04:27 AM
#8
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.
-
Jun 16th, 2009, 05:14 AM
#9
Frenzied Member
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
-
Jun 17th, 2009, 07:53 AM
#10
Thread Starter
New Member
Re: [RESOLVED] How can I pass a name selected from a ListView into another form
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
|