Solved

fill textbox in MDI Parent from Global Variable

Posted on 2004-09-06
8
497 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

910 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

24 Experts available now in Live!

Get 1:1 Help Now