Solved

Form call another form

Posted on 2008-06-21
8
175 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
 

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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

708 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now