2

I have a form with a DataGridView item that views a table from my databse. Another form adds a new row to that table and closes it self. In the first form, at the closing event of the second form, i want the first form to update/refresh/refill itself to the new data just added. I have tried this:

this.swimmersTableAdapter.Update(this.databaseDataSet1.swimmers);

And:

This.Update();

But unsuccessfully.

it does refresh it self when i stop debugging, and run it again, but ofcource it's not practical for the client/user.

any solutions ?

user3107990
  • 147
  • 1
  • 10
  • 2
    You could try the voted answer in this question; http://stackoverflow.com/questions/7008361/how-can-i-refresh-c-sharp-datagridview-after-update – mec Dec 16 '14 at 11:18

2 Answers2

0

Probably you need this...

Form 1:

public partial class Form1 : Form 
{
    public Form1() 
    {
        //'add a label and a buttom to form
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e) 
    {
        Form2 frm2 = new Form2(this);
        frm2.Show();
    }

    public void RefreshGrid() 
    {
        dataGridView1.Update();
    }
}

Form 2:

public class Form2 : Form 
{
    Form1 _frm1;

    public Form2(Form1 frm1) 
    {
        _frm1 = frm1;
        this.FormClosing += Form2_FormClosing;
    }

    private void Form2_FormClosing(object sender, FormClosingEventArgs e) 
    {
        _frm1.RefreshGrid();
    }
}
SiD
  • 511
  • 4
  • 15
0

You don't specific if doing C# WPF or Winforms.

But as noted via the comment, you could just rebind the new source, or do

YourForm.YourGrid.Items.Refresh();

If the This.Update() in your code was within the datagrid you are referring, try

This.Items.Refresh();
DRapp
  • 47,638
  • 12
  • 72
  • 142