Update Datagridview

Posted 16 January 2010 - 09:38 AM

Hi There;

I have a datagridview that filled with Norhwind's customer table, when double click on the selected record on the gridview, a window will open and display the data for the selected records. Once the 'Save' button is clicked on the new window after the changes is done, how could i update the datagridview to reflect the changes done?

I have attached here with my sample application that connect to Northwind database (SQL Server 2005) and work with Visual Studio 2008,

Replies To: Update Datagridview

Re: Update Datagridview

Posted 16 January 2010 - 10:27 AM

Hi there and welcome to DIC you DICHead.

First off, please post the code only. More importantly make sure that you post that is relevant to your problem.

You say you don't know how to insert values into a Database, right? Post the class where you are doing all the Database mumbo-jumbo. That way we can provide an example with your variable names and you'll be able to see what's happening much easier.

Re: Update Datagridview

First off, please post the code only. More importantly make sure that you post that is relevant to your problem.

You say you don't know how to insert values into a Database, right? Post the class where you are doing all the Database mumbo-jumbo. That way we can provide an example with your variable names and you'll be able to see what's happening much easier.

Can't wait! See ya soon!

His post said nothing about not being able to insert data. His problem is AFTER he does an insert from a child form, he wants to update the datagridview to reflect the newly inserted data.

eURe, hopefully you are using ShowDialog to show the child form. If so, after the ShowDialog, simple call the method that you use to show the data in the grid. This will now contain the new or updated data since its reading from the database.

Thanks for your solution, it's work fine if it's not in MDI container.However, my application desinged in MDI where it doesn't allow to have 'ShowDialog()' method.

E.g. Following code is not allowed in MDI

CustomerEntry.MdiParent = this.MdiParent;
if (CustomerEntry.ShowDialog() == DialogResult.OK)
{
// this will rebind the data to the datagridview
// so that the newest changes will show up.
this.customersTableAdapter.Fill(this.northwindDataSet.Customers);
}
}

Re: Update Datagridview

Posted 17 January 2010 - 08:18 AM

wait...so the form that has the datagridview is an MDI form? why? normally, you have a "Main" form that is the MDI with no controls other than menus. Then the menus open child forms, and those forms are what have the controls such as a datagridview.

So yours is like

MDI Parent --> child form with save button

rather than...

MDI Parent --> child form with datagridview --> child form with save button

is that correct?

EDITED: ok, nevermind, I think I know what you mean now.

You could pass a reference of the Form1 to Form2. Then before you close Form2 after a save, call the code to update the datagridview.

Re: Update Datagridview

Posted 17 January 2010 - 09:02 AM

eclipsed4utoo, on 17 Jan, 2010 - 07:18 AM, said:

wait...so the form that has the datagridview is an MDI form? why? normally, you have a "Main" form that is the MDI with no controls other than menus. Then the menus open child forms, and those forms are what have the controls such as a datagridview.

So yours is like

MDI Parent --> child form with save button

rather than...

MDI Parent --> child form with datagridview --> child form with save button

is that correct?

EDITED: ok, nevermind, I think I know what you mean now.

You could pass a reference of the Form1 to Form2. Then before you close Form2 after a save, call the code to update the datagridview.