Results 1 to 10 of 10

Thread: [RESOLVED] How can I pass a name selected from a ListView into another form

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2009
    Posts
    10

    Resolved [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

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    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")
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3
    Frenzied Member
    Join Date
    Oct 2005
    Posts
    1,286

    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
    Pete Vickers
    MVP - Device Application Development
    http://www.gui-innovations.com http://mobileworld.appamundi.com/blogs/

  4. #4

    Thread Starter
    New Member
    Join Date
    Jun 2009
    Posts
    10

    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.

  5. #5

    Thread Starter
    New Member
    Join Date
    Jun 2009
    Posts
    10

    Re: How can I pass a name selected from a ListView into another form

    Quote Originally Posted by petevick View Post
    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

  6. #6
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    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?
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  7. #7

    Thread Starter
    New Member
    Join Date
    Jun 2009
    Posts
    10

    Re: How can I pass a name selected from a ListView into another form

    Quote Originally Posted by Atheist View Post
    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:
    Code:
    Public selection
    and
    Code:
    Me.Label1.Text = selection

  8. #8
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    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.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  9. #9
    Frenzied Member
    Join Date
    Oct 2005
    Posts
    1,286

    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
    Pete Vickers
    MVP - Device Application Development
    http://www.gui-innovations.com http://mobileworld.appamundi.com/blogs/

  10. #10

    Thread Starter
    New Member
    Join Date
    Jun 2009
    Posts
    10

    Re: [RESOLVED] How can I pass a name selected from a ListView into another form

    Thanks a lot, Petevick

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width