Solved

Parent and child form evevts

Posted on 2013-06-06
11
417 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
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

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Sql server, import complete table, using vb.net 9 53
Sending receiving text messages in vb.net 15 63
vb.net 1 month apart 11 40
Calculate number of nights between two dates 5 93
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 …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

730 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