?
Solved

Parent and child form evevts

Posted on 2013-06-06
11
Medium Priority
?
425 Views
Last Modified: 2013-06-12
Hi All,

I have 2 win forms :

1. Parent
    Fill datagridview with data using open sub

2. Child
    Input data

I want to fill datagridview (refresh data) at parent form everytime the child save data.

How could I do it ?

Thank you.
0
Comment
Question by:emi_sastra
[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
  • 9
11 Comments
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 39225846
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 39225893
Hi jtoutou,

I've seen it.

It is quite different situation with my case.
After save, the child form is exited, while mine not the case.

I have 3 functions at child form :

1. Add
2. Update
3. Delete

Every time one of the function is done. I want to refresh dgv at parent form.

Thank you.
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 39227595
Hi jtoutou,

Any solution ?

Thank you.
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:emi_sastra
ID: 39227606
I use :

 Private WithEvents ChildForm As ChildForm

I could see ChildForm events, but I can not see sub/function (non events) inside that ChildForm.

How to make child form sub/function visible to parent form ?

Thank you.
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 39227732
I have this link :

http://stackoverflow.com/questions/16342016/vb-net-listen-for-parent-form-event-on-each-child-form

But I have no idea how to implements to my form.

At Child Form :

Private Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs)
     ---saving data

    -- I want to fired event at parent form to reload dgv data.
End Sub

What should I do ?

Thank you.
0
 
LVL 3

Expert Comment

by:xavixsb
ID: 39228336
you can't put the parent datagridview event code inside a public sub and call it everytime you need?
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 39228367
-you can't put the parent datagridview event code inside a public sub and call it everytime you need?
Yes, I could. But suppose there are some parent forms that call that child form.

Parent Forms :

1. Form1
2. Form2
3. Form3

All of the forms could call child form.
And suppose they have different sub name to fill datagridview or doing something.
The child form will have a lot to do to aware which parent form.

What should I do for this kind of situation ?

Thank you.



Thank you.
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 39228375
A great way is child form notify parent form when doing something is done.

Just like using at parent form :

 Private WithEvents ChildForm As ChildForm

We could control Child Form Events.

Thank you.
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 39228904
I try below, but at the parent form, the event does not fired.

Public Class frmParent

    Private WithEvents frmChild As frmChild

    Private Sub frmParent_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim frmChild As New frmChild

        With frmChild

            .ShowDialog()
        End With

    End Sub

    Private Sub frmChild_DidSomething(ByVal sender As Object, ByVal e As System.EventArgs) Handles frmChild.DidSomething

        MsgBox("You Are At Parent ...!", MsgBoxStyle.Information, Me.Text)

    End Sub

End Class

Public Class frmChild

    Public Event DidSomething(ByVal sender As Object, ByVal e As EventArgs)

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        RaiseEvent DidSomething(sender, EventArgs.Empty)
    End Sub

    Private Sub NowDoSomething(ByVal sender As Object, ByVal e As EventArgs) Handles Me.DidSomething
        MsgBox("You Press " & sender.name)
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        RaiseEvent DidSomething(sender, EventArgs.Empty)
    End Sub

 End Class

What's wrong with my code ?

Thank you.
0
 
LVL 1

Accepted Solution

by:
emi_sastra earned 0 total points
ID: 39228921
Problem solved.

 Private Sub frmParent_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim frmChild As New frmChild  'change to  frmChild = New frmChild

        With frmChild

            .ShowDialog()
        End With

    End Sub

Thank you.
0
 
LVL 1

Author Closing Comment

by:emi_sastra
ID: 39240401
I solve my problem.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

777 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