Click here to Skip to main content
15,896,348 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I have two forms (Form1 & Form2).

Form1 contains a DataGridView control and Add button.
Form2 contains TextBoxes & save Button.

Here is my running forms
1st: Form1 will appear when click Add button
2nd: Form2 will appear here adding text to text boxes and when I click the save button it's saved to database and Form1 still stays there.

My question is this: I want to show existing Form ie Form1 with updating data and dont want to show a new Form1.

I hope you understand the concept.

Please help me out
Posted
Updated 19-Jan-11 21:34pm
v2
Comments
Dalek Dave 20-Jan-11 3:35am    
Edited for Grammar, Syntax and Readability.

You just need to use it as:
C#
Form1 m_frm = new Form1();
private void button_add_Click(object sender, EventArgs e)
{
    m_frm.Show();
}

and in Form 1 you need to handle the closing event:
C#
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
  e.Cancel = true;
  this.Hide();
}
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 20-Jan-11 0:44am    
Should be enough. Second sample is important. My 5.
JF2015 20-Jan-11 0:49am    
Thanks a lot. By the way - I really appreciate your detailed answers in the Q&A section. I tend to post quick/short answers but your's are very detailed and well thought out - awesome work!
Sergey Alexandrovich Kryukov 20-Jan-11 15:18pm    
This time, your comment is very detailed and well thought out -- thank you. :-)
ks ravi 20-Jan-11 0:57am    
hi JF2015,
thanks for reply,first logic is working but i got two Same Form1 windows form atfer save button clicked.But actually i want like old Form1 should not appear Or if updates to same old Form1 is also ok. please reply with an exp.
Dalek Dave 20-Jan-11 3:35am    
Spot on, good answer.
Hi Ravi..

Dont use for From.Show only use Form.ShowDialog().

get all the Datas from Old Form by Accessing Old Form Properties..

And u want to do any Action in New Form.. Set Perperties in new form
.and
do action in NewForm Load event.


Regards,
Saran.t
 
Share this answer
 
Comments
ks ravi 20-Jan-11 1:25am    
hi saran,
thanks for reply, its working and showing the new updated Form1. i guess you got my that actually i want like old Form1 should not appear while new Form1 comes Or if updates to same old Form1 is also ok. please reply with an exp

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900