DataGridView Refresh from child Form

Posted on 2010-11-08
Last Modified: 2012-05-10
my main form is a datagrid view of customers, I have a menuStrip with icons where I can add customers which opens a child form, when i click on the cave button I would like to close the child form and update the parent form, how can I do this ?
Question by:prowebinteractiveinc
  • 3
  • 2
LVL 10

Accepted Solution

Umar Topia earned 500 total points
ID: 34090353
If you are using for opening a child window
then you can simply use the following approach:

In Parent Page Create one JavaScript function:-

// do something

In Child Page on some event, call the parent funciton


Author Comment

ID: 34090399
its not a web based application im working with, its a windows application
LVL 15

Expert Comment

ID: 34096033
It is easy but it requires that Child Form knows Parent Form. This breaks encapsulation concept.

I think you do´nt need do it from parent form.

You are using a modal child form. Then use the DialogResult.

Note that there are some Dialog Result values.
You assign a Dialog Result to each Button on Child Form that terminates the action (Ok, CanCel, Yes ...)

   Dim Result = ChildForm.ShowDialog
   Select Case ReSult
       Case DialogResult.Ok
          Refresh the Dgv
       Case DialogResult.Cancel
          Other Options

Note that when you press a button with DialogResult asigned, ChildForm is closed.
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline


Author Comment

ID: 34098836
I dont expect someone to just write my code for me, however I just opened VB.NET for the first time, last week, and have poking around since.. is there some sample code you can show me, the code above is where I need the parent refresher
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click


        cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\users\jason\documents\visual studio 2010\Projects\WindowsApplication2\WindowsApplication2\Database1.mdb;")


        str = "INSERT INTO customers (customer_fname, customer_lname) VALUES('" & Me.TextBox1.Text & "','" & Me.TextBox2.Text & "')"

        cmd = New OleDbCommand(str, cn)




    End Sub

Open in new window

LVL 15

Expert Comment

ID: 34104959

   Dim Dt as new DataTable, Da as new OleDbDatAdapter(cmd)
   TheDgv.DataSource = Dt

Author Comment

ID: 34107582
Ive played around with what you gave me and I cant get it to work ??

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

747 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

16 Experts available now in Live!

Get 1:1 Help Now