Solved

Form call another form

Posted on 2008-06-21
8
181 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
Industry Leaders: 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Title # Comments Views Activity
Generate Numbers in JQuery file 11 72
VB.Net - String Manipulation Scenario 2 31
Generate Unique ID in VB.NET 21 104
Cannot kill Excel from taskmgr after Excel Export in VB 2014 6 39
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

726 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