Solved

DataGridView Refresh from child Form

Posted on 2010-11-08
6
694 Views
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 ?
0
Comment
Question by:prowebinteractiveinc
  • 3
  • 2
6 Comments
 
LVL 10

Accepted Solution

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

In Parent Page Create one JavaScript function:-

ParentTest()
{
// do something
}

In Child Page on some event, call the parent funciton
ChildTest()
{
window.parent.ParentTest();
}

0
 

Author Comment

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

Expert Comment

by:x77
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.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:prowebinteractiveinc
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

        'Try

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

        cn.Open()

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

        cmd = New OleDbCommand(str, cn)

        cn.Close()

        <!-- THIS IS WHERE I NEED REFRESH CODE -->

        Me.Close()

    End Sub

Open in new window

0
 
LVL 15

Expert Comment

by:x77
ID: 34104959

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

Author Comment

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

920 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

13 Experts available now in Live!

Get 1:1 Help Now