?
Solved

Refresh Datagridview from another form

Posted on 2016-11-09
1
Medium Priority
?
72 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
[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
1 Comment
 
LVL 13

Accepted Solution

by:
Dustin Saunders earned 2000 total points
ID: 41880993
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 …
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month12 days, 2 hours left to enroll

752 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