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
Solved

fill textbox in MDI Parent from Global Variable

Posted on 2004-09-06
8
511 Views
Last Modified: 2010-04-23
I have an MDI Winforms App in VB.Net.

When I select a certain Row in the datagrid in the Child Form, I then set a Public Variable (contained in a module) to a certain field value from the database.  Then, on closing the Child form, I want to set the textbox1.text (say) on the Parent Form to the value of that Public Var.

On closing Child form, I tested the Pub Var with a MsgBox - fine - the Pub Var value is correct.
But when I close the Child form, the value does not appear in the textbox on the Parent form.

What 'event' do i need to make this happen?
Is is something to do with using 'Me' object??

Thanks
0
Comment
Question by:Sigh_Man
  • 4
  • 4
8 Comments
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 11994881
Hi Sigh_man,

First why use a public variable in a module, just use a public property in your parent form

parent form

Private _mytext As String
    Public Property mytext() As String
        Get
            Return _mytext
        End Get
        Set(ByVal Value As String)
            _mytext = Value
            textbox1.text = _mytext
        End Set
    End Property

child form

    Private Sub yourchildform_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
        CType(Me.MdiParent, yourparentform).mytext = TextBox1.Text
    End Sub

Second, you do now that controls on the parent form will ALWAYS be in the foreground.
In other words controls on the parent form are useless.


0
 
LVL 1

Author Comment

by:Sigh_Man
ID: 11996111
Ronald,

I guess I just threw variables into the module because this is the way I first learned to set values and access them using the different forms in my applications.  I guess I just stuck with doing it that way because it answered my problem at the time.  BUT I SEE YOUR POINT!!   :D

Also, your comment...
>>>Second, you do now that controls on the parent form will ALWAYS be in the foreground.  In other words controls on the parent form are useless.

Did you mean to say "In other words controls on the CHILD form are useless"...??  Or am I out of my depth with the terms???!!   :D

In the current application, I have designed my frmMainWindow to have a panel containing text boxes and other stuff.  The idea is that even if a user opens a Child form, they can ALWAYS see certain info about the ActiveClient - surname, Date of Birth etc - all in the panel to the right of the MainWindow.  The Child form does not cover the panel.  The problem is that I need to close the Child Form (say, the 'Set Active Client' form) and once set, I need to close the form and return to the Main Window parent form (which should then be displaying the active Client detail in the panel.
0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 11996174
Hi Sigh_Man,

No, I meant what I said :-) if you maximize the child form, you will see that the child form is behind the panel.

Do you want to close the child window programaticaly or does the user close the child form.

0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

 
LVL 1

Author Comment

by:Sigh_Man
ID: 11996250
Aaaah, I know what you mean.  Yeah, I'm aware that the Child form will be below the panel on the Parent form.  I have designed the Child Form to accommodate this.  (Is using a panel the best way for this, or is it possible to somehow split the screen, or somehow redefine the MdiChild area on the Parent form (now I really am guessing!)).

And, the user will close the form (for now, at least).
0
 
LVL 25

Accepted Solution

by:
RonaldBiemans earned 125 total points
ID: 11996282
(Is using a panel the best way for this, or is it possible to somehow split the screen, or somehow redefine the MdiChild area on the Parent form (now I really am guessing!)).

Unfortunatly no, it would be a great feature though

If the user closes the form you can do as I suggested

parent form

Private _mytext As String
    Public Property mytext() As String
        Get
            Return _mytext
        End Get
        Set(ByVal Value As String)
            _mytext = Value
            mainformtextbox1.text = _mytext
        End Set
    End Property

child form

    Private Sub yourchildform_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
        CType(Me.MdiParent, yourparentform).mytext = childformTextBox1.Text
    End Sub
0
 
LVL 1

Author Comment

by:Sigh_Man
ID: 11996385
I have just realised that in my Child Form (Set Active Client) the user clicks on the desired client name in a datagrid and hits the "Open" button.  This sets the active client to the one the user selected then closes the Child form -- so in answer to your question, the Child form closes programmatically.  Does this change the solution?
0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 11996417
not really :-)

The property gets set in the closing event of the child form, so it doesn't matter if it is done manually or programmaticaly
0
 
LVL 1

Author Comment

by:Sigh_Man
ID: 11996516
Excellent.

Thanks.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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
VB.NET 1 28
cannot connect to sqlserver 8 34
Passing data between Forms 3 20
VB.net DataGridView show bit field as Text column not CheckBox column 5 18
This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

856 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