Solved

Parent and child form evevts

Posted on 2013-06-06
11
420 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

707 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