0

Hello I have form1 and form2

private void form1_Load(object sender, EventArgs e)
{
//codes to display db
}

then I use form2.ShowDialog(); to open the form because I dont want multiple windows

then in my form2 i have to delete something so the form1 must update the display.

 private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
//codes to delete
  form2_Load(sender, e); //so the form2 will reload
}

First I have to open first form1 before I can open form2. How can I update/refresh the form1 whilst still in form2? EDIT:
The only thing I want to refresh in the form1 is the dataGridView

Fiendcoder1
  • 119
  • 1
  • 1
  • 12

2 Answers2

0

Actually it's not good idea to update other form directly from the current form. It's better to design a mediator using delegate and callbacks to update other forms when your user is working in current and active form.

Mohammad Nikravesh
  • 947
  • 1
  • 8
  • 27
  • My `form1` is just use for queries and `form2` is more on technicals. So I think it's okay just to refresh/update the display – Fiendcoder1 Jan 19 '17 at 01:49
-1

This question depends on Does form2 know how to access form1?

If so, you can call form1.Refresh() (or some other public method) to ask form1 update the list. (Of cause, you have to override the Refresh method, or create your own public method).

If not, maybe you can consider to use Singleton pattern on your form1.

--

Moreover, if form2 always created by form1, you can consider to open form2 like this (must write in form1)

Form2 form2 = new Form2();
form2.Open(this);
//-- or
form2.OpenDialog(this);

If so, you can access form1 in form2 by calling this.Parent.

Community
  • 1
  • 1
J.C
  • 633
  • 1
  • 13
  • 27
  • This does not answer the question. If you still have to ask questions, use comments. – Luc Morin Jan 19 '17 at 01:29
  • @LucMorin I have update my answer, and I think this all problem can be solved by Singleton Pattern... – J.C Jan 19 '17 at 01:34