?
Solved

Form call another form

Posted on 2008-06-21
8
Medium Priority
?
183 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 800 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 1200 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
Technology Partners: 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
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.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month13 days, 19 hours left to enroll

801 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