Solved

fill textbox in MDI Parent from Global Variable

Posted on 2004-09-06
8
481 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 25

Accepted Solution

by:
RonaldBiemans earned 125 total points
Comment Utility
(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
Comment Utility
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
Comment Utility
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
Comment Utility
Excellent.

Thanks.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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 …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

744 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

17 Experts available now in Live!

Get 1:1 Help Now