开发者

adding the details in one form and details will be updated in another form

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 bo开发者_运维知识库xes ...

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...


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


If I am understanding your question you need to do the following:

  1. You need to create a click event for your 'Add' button that will add the new record to your database.
  2. Once the record is added you can close your form and on your form close you can refresh the datagrid in Form1.

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
    }

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜