- I create a winform
- I´m adding a datagridview by dragging a table from data sources
- the result: I´ve got a winform with a datagridview and a bindingnavigator
- I´m adding a second datagridview to the same winform by dragging another table from data sources
- the result: same as bullet 3, but now with two datagridviews; a second bindingnavigator is not added though, don´t ask me why!
- I copy the existing bindingnavigator and a adapts the copy to the second datagridview
- I look into the .Designer.cs file, and it looks perfect regarding consistency
Now to the problem - even though both datagridviews have their own BindingNavigatorSaveItem_Click method, with code pointing out their respective bindingsources... it´s not possible to save changes from the second datagridview to the database!
Anyone seen this? Any suggestions what to do?
views:
36answers:
2
A:
I would suggest to set the DataSource property of the DataGridView in code through the use of a DataTable or object collection instead of using a bindingnavigator.
dretzlaff17
2010-10-27 13:56:35
@dretzlaff17Thanks, you made me think in the right direction. I still use the automated stuff, though. The solution (for me) was to change UpdateAll to Update.The thing is, UpdateAll should do it, and is "predefined" in the Save-event-handler... but some mr Gates well hidden bug makes it a bit inconsistent, especially in scenarios as stated in my Question.
Jack Johnstone
2010-10-27 16:24:38
A:
I solved it like this (I thank mr/mrs/miss dretzlaff17 who started up some processes in what´s left of my doped brain)
private void tableMeLikeBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
try
{
this.Validate();
this.tableMeLikeBindingSource.EndEdit();
// IMPORTANT: the following predefined generic Update command
// does NOT work (sometimes)
// this.tableAdapterManager.UpdateAll(this.rESOURCE_DB_1DataSet);
// instead we explicitely points out the right table adapter and updates
// only the table of interest...
this.tableMeLikeTableAdapter.Update(this.rESOURCE_DB_1DataSet.TableMeLike);
}
catch (Exception ex)
{
myExceptionHandler.HandleExceptions(ex);
}
}
Jack Johnstone
2010-10-27 16:23:35