Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

fill textbox in MDI Parent from Global Variable

Posted on 2004-09-06
8
Medium Priority
?
531 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
Independent Software Vendors: 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!

 
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 500 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
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 …
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

972 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