Solved

Parent and child form evevts

Posted on 2013-06-06
11
404 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
  • 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
 
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
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 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

759 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

23 Experts available now in Live!

Get 1:1 Help Now