Solved

Form call another form

Posted on 2008-06-21
8
182 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

717 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