views:

248

answers:

2

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: 

Fill the grid with data from the database again?

Petoj
+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
i use Data Bindings and fill this with data set .
persian Dev
OK, so if your second form works on the same DataSet, the values in the DataGridView will be automatically updated.
Thomas Levesque
no second form use another dataset object
persian Dev
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
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
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