Reputation: 17701
I have two forms.. form1 and form2 in form1 i have gridview with three columns and in form2 i have two buttons one is add button and second one is update button and i have three text boxes ...
i have done like this if we click any of grid view column in form1 then the form 2 will be displayed with textboxes fill with grid view row values ..
now i need to add another row to gridview by using this add button in form 2 .. so when i fill the textboxes and click on add button the form 2 will be closed and the form 1 grid view is update automatically with these details ...
i am using winforms application and using linq to entites for doing databse operations ..
any idea pls.... for doing this...
Upvotes: 1
Views: 423
Reputation: 247820
If I am understanding your question you need to do the following:
I do something similar to this in several of my applications. On Form1 when opening Form2 you can create something like this:
private void ShowForm2()
{
DialogResult addResult = new Form2().ShowDialog();
if (addResult == DialogResult.OK)
{
//your code to populate your datagrid
}
}
Then on Form2 your Add button click
private void AddRecordButton_Click(object sender, EventArgs e)
{
try
{
// code to add the record to your database
//then use the DialogResult OK
DialogResult = DialogResult.OK
}
catch
{
//if it fails set DialogResult to Abort
DialogResult = DialogResult.Abort
}
}
Upvotes: 0
Reputation: 62276
Declare event in form2 for AddRow, subscribe to that event in form1, when button clicked on form2 and new row have to be added, form2 raises that event, so form1 handles it and shows it on DataGrid.
Tutorial for event implementation you can find here:
http://msdn.microsoft.com/en-us/library/aa645739(v=vs.71).aspx
Upvotes: 1