CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2011
    Posts
    2

    Multi Forms and List Boxes

    Ok, Im having trouble passing a value from one form back to another using a listbox... The user clicks a button in the main form to bring up an instance of another form (form2.show). In that form, the user then then selects a number 1-5 and then presses done:

    Code:
    Private Sub frmPlayer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim x As Integer
            If lboNumber.Items.Count = 0 Then 'list box is empty
                For x = 1 To 5
                    lboNumber.Items.Add(x.ToString)
                Next
            End If
    
        End Sub
    How do I pass that value back to the main form as a value when the user clicks done?

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Multi Forms and List Boxes

    Create a PUBLIC property, and you can call it from a different form. Not DIM'd
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: Multi Forms and List Boxes

    Simple, I'd set the Done button ( on the second form ) 's DialogResult property to OK, then show Form 2 with ShowDialog, as in :

    Code:
    Dim f2 As New Form2
            If f2.ShowDialog() = Windows.Forms.DialogResult.OK Then
    ....

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

Featured