i have to windows forms . first form shows list of records from sql . when you click some cell of a record in datagridview it shows second form . in second form you can edit and update the record . i want datagridview to be updated automatically when user close second form . what should i do ?
+1
A:
Are you using data bindings, or do you manually fill the grid ? With data bindings its very easy... if the data is contained in a DataTable
and you change it somewhere, the change will be reflected automatically in the DataGridView
. It also works with objects that implement INotifyPropertyChanged
, and lists that implement IBindingList.
If you're not using bindings, you can :
- locate the cell that contains the edited value, and update it manually, OR
- refill the entire grid
Thomas Levesque
2009-09-24 19:18:13
i use Data Bindings and fill this with data set .
persian Dev
2009-09-25 06:56:12
OK, so if your second form works on the same DataSet, the values in the DataGridView will be automatically updated.
Thomas Levesque
2009-09-25 08:16:25
no second form use another dataset object
persian Dev
2009-09-25 15:39:34
why ? if the second form modifies the data displayed in the first, you should use the same dataset... You can pass it as a constructor parameter for instance
Thomas Levesque
2009-09-25 15:46:00
pas from second form to first form you mean ?lets explain it more . in second form user can delete a record . if he/she turn back to first form , he/she still can see that record . i want datagridview to be updated , because if user click on that record (which has been deleted) , it will cause error .
persian Dev
2009-09-25 16:01:37
No, you didn't understand me. Both forms have to work on the same DataSet, that way the dataset itself will notify the DataGridView in the first form when a row is added/deleted/modified in the second form. So when you open the second form, you must pass the dataset to it so that both forms use the same dataset
Thomas Levesque
2009-09-25 17:23:45