Update data in Grid on form1 from form2.
-
Hello, I am using Datagrid to show records and there are two buttons for Add new record and edit record. when add or edit button is clicked new form is opened where user enter data n after clicking ok on that form activation returns to datagrid form. Now the problem is, I want to execute UpdateGrid() method which shows updated data into grid. This can be called on Activated event of the form but if that form is MDI child Activated event does not work. so after editing or add new record I don't have any event to raise to update data into grid. If I don't make grid form as MDI child Activated event work properly but that doesn't fullfill my requirement. So plz could u tell me how to solve this problem. I tried making UpdateGrid() function as public and calling this function from add or edit on close event. but it haven't update my grid. Thank you for your support. Inpreet Singh
-
Hello, I am using Datagrid to show records and there are two buttons for Add new record and edit record. when add or edit button is clicked new form is opened where user enter data n after clicking ok on that form activation returns to datagrid form. Now the problem is, I want to execute UpdateGrid() method which shows updated data into grid. This can be called on Activated event of the form but if that form is MDI child Activated event does not work. so after editing or add new record I don't have any event to raise to update data into grid. If I don't make grid form as MDI child Activated event work properly but that doesn't fullfill my requirement. So plz could u tell me how to solve this problem. I tried making UpdateGrid() function as public and calling this function from add or edit on close event. but it haven't update my grid. Thank you for your support. Inpreet Singh
Instead of handling events on the
DataGrid
, it's better to handle events on theDataSet
if you're using one, or rather theDataTable
(s) contained in theDataSet
. TheDataTable
has many events (likeRowChanged
andRowDeleted
) you can handle. These are fired before or after (depending on which events you use) the underlying data source is updated. TheDataGrid
itself has no effective means to know when the data source was changed. If you're not using aDataSet
, you can either use appropriate events for theIList
orIListSource
implementation (like anArrayList
) if any are exposed, or add events by extending the class or creating your own wrapper class.Microsoft MVP, Visual C# My Articles