locked
Form wating a parameter from another from RRS feed

  • Question

  • Hi, i'm using VB.NET 2005. What i'm trying to do, is from one form, open anotherone and perform a search to SQL Server 2005 and the value selected return it to the first form.

    I actually do it, opening the second form, performing the search and when i select an item, call a sub in the first form sending the info, close the second form, and try to display the information in two labels in the first form, but the labels doesn't refresh. if i show the info retrieved from the second form in a message box, it displays, but the labels doesn't chage its text . . .

    Wednesday, August 23, 2006 12:08 AM

Answers

  • Care to show us some code ?

    If it were me I would create parameters on the first form, create the second form doing the search and when you select an item in this second form, I would use the properties on the first form to set the selected values.    The setting of the properties would set the labels.

    This way I can set the labels by simply setting the properties on the first form.

    A simple code example

    Public Class Form1

    'Setting this property will update the Label on Form1
        Public Property ID() As String
            Get
                Return Me.Label1.Text
            End Get
            Set(ByVal value As String)
                Me.Label1.Text = value
            End Set
        End Property


        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
     '//Create a Form 2 and provide a reference from this form
            Dim x As New Form2
            x.form1ref = Me
            x.Show()
        End Sub

    End Class


    Public Class Form2
        Private f1 As Form1

        Public Property form1ref() As Form1
            Get
                Return f1
            End Get
            Set(ByVal value As Form1)
                f1 = value
            End Set
        End Property

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            f1.ID = Me.TextBox1.Text '//Set the selected value or Textbox contents on form2 and pass back to form1
            Me.Close() '//Close Form
        End Sub
    End Class

    Wednesday, August 23, 2006 4:23 AM