Hi,
I have a DGV with a datasource of a BindingSource. THe BindingSource has a DataSource of a typed DataSet table. These have been linked using the designer.
On a button, I want to change the rows that the DataSet table contains, and then have the bindingSource and DGV update automatically (as well as any other controls bound to the bindingSource).
Currently, I make the change to the DataSet using tableAdapter.Fill(DataSet.Table) and the bindingSource and DGV do not update.
I've tried adding resetbindings to the bindingSource.. but no avail.
Any ideas... please.
Also, is there any standard doc on this type of thing.. e.g. how do you ensure controls are refreshed ..
Thanks,
TWK (David)

DataSet change does not update bindingSource.
Ben Dot Smith
Call the dataset.clear method before the fill. This will clear all rows from all tables within the dataset. If this is inappropiate(need to retain other table data within the dataset), loop through each row in the table and delete it.
Ria
You can refresh in two manners.
1. Tell the control to refresh it's data
2. Tell the data to throw an refresh event so all controls get refreshed
I personally always go for option 2.
StefanoVS2005
amz
I dont think I am clear on the issue.
I get the correct ID's. But I am using a DISCONNECTED update...
Which is basically
I was wondering How other people are doing it , and if there is a better way .
I am following this up on the thread below, and i have posted a quick example to regenerate the behavior.
http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=315095&SiteID=1
Thank you
SyedIrfan
There is a good article in the msdn about this.
Basically what you do is you define one dataset primairy key per data table. You set this pramairy key to autoincrement with the seed of minus 1. Database autonumbering (IDENTITY Column) always increment positive. This way you can keep track of database records and your new records. When you update your datatable against the database be sure to use the SELECT @@IDENTITY as ID column afther your insert query. This returns the primairykey value to your dataadapter. You also need to tell it that the first returned row contains the updated values. You then merge the result back into your original dataset using Merge(something, false). What the false does is it doesnt destroy the changes.
For instance. I send a row to the database containing ID -15. The database inserts the row into the table and returns the ID of 15. When the row gets merged into my dataset, the dataset will see -15 is changed to 15 and will change the -15 value to 15.
Hope you can follow :)
Try searching MSDN, there are some really good atricles on ADO.NET there!
WATT
Thanks for responding...
I tried the ResumeBinding, but unfortunately it did not work. From looking at the doc it only is useful for simple bound fields not DGV.
I just tried re-setting the DataSource of the bindingSource within code and this seems to trigger a refresh of the bindingSource. There must not be any event in the DataSet that bubbles up to the bindingSource for a refresh, i.e. always reset the bingingSource.DataSource after changing the DataSet.
I'll keep the SuspendBinding/ResumeBinding in mind for simple bound fields.
Cheers,
TWK (David).
Maik Duwi
Try calling the ResumeBinding method of the BindingSource afther you fill the datasource.
Controls are generally refreshed useing the CurrencyManager.Refresh() method.
For more information look here :
http://msdn2.microsoft.com/en-us/library/ms158152.aspx
Naren Datha
No idea,
I always use one DataSet in memory and just merge it with whatever results I get back from the database.
That way the pointer wich points to my table never gets broken.
dahall
I only use one DataSet too, however I was really referring to when the construct tableAdapter.Fill(DataSet.DataTable) is used - does this create a new DataTable in the DataSet or replace it
On further investigation, I have found the following to also refresh the bindingSource/DGV thanks to other forum entries:
this
.BindingContext[dataGridView.DataSource].EndCurrentEdit();dataGridView.Refresh();
I think this is a better way of refreshing than my original efforts.
I also have an issue where DataSet.RejectChanges() does not update the bindingSource causing a subsequent bindingSource.EndEdit() to re-apply the changes. I'm working through this one, but the above doesn't seem to fix.
eyedealist
I prefer this "Merge" method too...
I was wondering how do you like to proceed with the disconnected updates
GetChanges() > Update > Merge > AcceptChanges()
does not work for me if there are inserts (No autonumberID)
GetChanges() > Update > RejectChanges() > Merge > AcceptChanges()
does not work if you have deletes...
I had to do something like :
public static
void ApplyUpdates(DataSet myDataSource, DataSet updates){
if (updates == null)
{return;}
foreach (DataTable dt in myDataSource.Tables){
DataRow[] inserts = dt.Select("", "", DataViewRowState.Added);
foreach (DataRow dr in inserts){
dr.RejectChanges();
}
}
myDataSource.Merge(updates);
myDataSource.AcceptChanges();
}
Isn't this too much work
Any suggestions