Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Parent and child form evevts

Posted on 2013-06-06
11
Medium Priority
?
431 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
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 …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

609 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