Solved

Form call another form

Posted on 2008-06-21
8
180 Views
Last Modified: 2010-04-23
I have a form that within it call another form , what I need is , when I Open the another form
lets say child one. I add new record , I want this record to be shown or saved in a variable
so I can use it in the main form.
0
Comment
Question by:Ahmadal_najjar2003
  • 3
  • 3
  • 2
8 Comments
 
LVL 48

Expert Comment

by:jpaulino
ID: 21837608
You want to pass some information between forms ?
0
 
LVL 48

Assisted Solution

by:jpaulino
jpaulino earned 200 total points
ID: 21837651
Don't have shure but if it is you can do this way ...

In the target form do this:

Public Class Form2

    Private myString As String

    Sub New(ByVal str As String)
        InitializeComponent()

        myString = str
    End Sub

    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        MessageBox.Show(myString)
    End Sub

End Class

Then when you create a new instance of the form you must fill the string:

Dim frm As New Form2("test")
frm.Show()

You can also add a module and declare the variable as public and then you can use it on all your project.
0
 
LVL 18

Accepted Solution

by:
Priest04 earned 300 total points
ID: 21837847
' In chikd form

Dim m_RecordValue As String

Public ReadOnly Property RecordValue() As String
    Get
        Return m_RecordValue
    End Get
End Property

When you close the childform, you will set m_RecordValue to the value of the added record
and then in main form

Dim frm As New ChikdForm
frm.ShowDialog()
dim retVal As String
retVal = frm.RecordValue


Goran
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:Ahmadal_najjar2003
ID: 21838996
Both Solution Give me very good Idea , But the second solution of Priest04 , What I Need in this moment.

I think for another solution like this :
  1- first add public variable within the MainForm of the projcet itself as = nothing
      Public ReturnedFormString As String = Nothing
   2- second , in the called form itself within Load event , set also the value = nothing
      mainform.ReturnedFormString = Nothing
   3- In any place within the called (child form) set the value you want
      for example
      when save the new data set
      mainform.ReturnedFormString = ComboBox.text
   4- use this value within the caller form if you wish .
       dim str as string = mainform.ReturnedFormString
0
 
LVL 18

Expert Comment

by:Priest04
ID: 21839416
That is not a very good practice, it makes code maintaining very hard. Sometime in the future you will not know in what places you set this value, whicih could cause logical errors, and they are hardest to solve.
0
 

Author Comment

by:Ahmadal_najjar2003
ID: 21840081
Thats right. So that I reset this value to nothing in loading the form.
0
 
LVL 18

Expert Comment

by:Priest04
ID: 21840522
Nevertheless, its the same. Good practice is to have some property that will return value to the form that needs this value.

Goran
0
 

Author Closing Comment

by:Ahmadal_najjar2003
ID: 31469408
Thank alot
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question