Solved

Refresh Datagridview from another form

Posted on 2016-11-09
1
25 Views
Last Modified: 2016-11-10
Hi,

I have two forms. I call FORM2 from FORM1. When in FORM2 and apply some changes with button control i need refresh Datagridview in FORM1 before exit FORM2.


Call FORM2 from FORM1:

Dim f As New form2(myparameter)
f.ShowDialog()

Code for Button in FORM2:

 Dim f1 As New form1
 F1.ShowGridRecords()  ' Procedure to bind grid
 f1.MyDgView.Refresh()

But with this approach not work, can someone help.

best regards

Example in attached image
img6.png
0
Comment
Question by:rflorencio
1 Comment
 
LVL 12

Accepted Solution

by:
Dustin Saunders earned 500 total points
Comment Utility
You would need to create an event on the sub form that the parent would subscribe to.  When that event is triggered on the the sub form, then you can trigger a refresh method.

Here is an example:
'Here is the code for parent form
Public Class ParentFormClass
    Public Sub MyLogic()
        MessageBox.Show("My Logic is Running!")
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        MyLogic()
    End Sub    

    'This is the way that you pass an instance of parent to child
    Private Sub ShowChildFormButton_Click(sender As Object, e As EventArgs) Handles ShowChildFormButton.Click
        Dim f As New ChildFormClass(Me)
    End Sub
End Class

'Here is the code for child form
Public Class ChildFormClass
    Private MyParentForm As ParentFormClass

    Public Sub New(form As ParentFormClass)
        ' This call is required by the designer.
        InitializeComponent()
        ' Add any initialization after the InitializeComponent() call.
        MyParentForm = form
    End Sub

    Private Sub CallParentFormMethodButton_Click(sender As Object, e As EventArgs) Handles CallParentFormMethodButton.Click
        MyParentForm.MyLogic()
    End Sub 
End Class

Open in new window

via http://stackoverflow.com/questions/33383171/how-can-i-trigger-parent-form-event-from-child-form
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

743 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

17 Experts available now in Live!

Get 1:1 Help Now