Form:1 contains a user control, on the cell click event of the user control开发者_StackOverflow社区 grid I show form:2. When I update values in form:2 and close it, the user control grid in form:1 should get refreshed. I did the same as in this link though it does not produce any error, the user control grid did not get bind!!!
Please let me know how this can be accomplished.
Use the advantage of ShowDialog() method.
If a form is displayed as modal, the code following the ShowDialog method is not executed until the dialog box is closed. However, when a form is shown as modeless, the code following the Show method is executed immediately after the form is displayed.
private void CellClicked()
{
Form2 form2 = new Form2();
form2.ShowDialog();
//Execution stops here until you close the form2.
myForm1Control.Values = form2.GetValues();
}
I have implemented this functionality using delegates,
Declare delegate in user control,
public delegate void Delegate1(datatype param1,datatype param2, datatype param3);//should be similar to the method used to bind user control in form1
public Delegate1 RefreshGrid;
In cell click event of user control, after form2.ShowDialog()add
RefreshGrid(param1,param2,param3);
In form1's constructor after intializecomponent() method add
usercontrolID.RefreshGrid = MethodUsedToBindUserControl;
精彩评论