Question on DataSource Updates

  • Thread starter Thread starter Aaron Smith
  • Start date Start date
A

Aaron Smith

I have a question. When using a DataGrid, I want to make sure the
datasource gets updated every time the user makes changes and navigated
to a new row.

The way I am doing it now, is I have a PositionChanged event on the
BindingContext. When it changes I call a save routine. The save routine
checks to see if the first column in the datagrid is empty (primary key)
and if it is, cancels the current edit and saves a variable to notify
the save routine to start a new edit when done. It then updates the
datasource and before it finishes checks that variable to see if a new
edit needs to be started for the new row and then initiates a AddNew...
This seems like a bandaid rather than a proper way of doing it.. At
least to me right now.. Is this the proper way or is there a better way
to handle this? I was going to try to use the rowchanged event, but I
couldn't call the save routine in my form...

Thanks,
Aaron
 
Hi Aaron
From what source do you fill this grid ?
if a data grid is bound to a datatable, then when u make changes, the
datatable is changed too....after that, u can update the datasource using
that datatable ( passing the dataset that include that table to the update
method if the related dataadaptor.) . but if you want these changes to be
reflected on your database . do that before you apply the accept changes
method on your datatable foe when you do that the datatable erase the
old values and keep only the new ones and this way the update command of
the adaptor can't be constructed properly . if you want to ignore this
changes however , just apply the reject changes method on the datatable
Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top