I was going through the example at http://msdn2.microsoft.com/en-us/library/ms229684.aspx
I fixed the small problem with the EditView constructor with these 2 lines:
if (drView["Discontinued"] is DBNull) drView["Discontinued"] = false; cbxDiscontinued.DataBindings.Add("Checked", CurrentBindingSource, "Discontinued"); |
However, the application works fine for most part, except when I tried to add a new record a second time. It seems that after the AddNew call, the current item of the productsBindingSource somehow points to the first item in the list instead of the new item. This leaves the EditView dialog editing the first item, instead of the new item. I tried calling MoveLast immediately after AddNew, but to no avail.
(2)
In the "Smart Task menu" of a datagrid, there is a "Generate Data Forms". However, I discovered that the generated code will give compilation errors. I have to fix them by amending the constructor of the generated EditViewDialog form to take in a BindingSource parameter. Could anyone confirm this I'm using VS.Net 2005 Professional v8.0.50727.42.
(3)
In a separate project, I wanted to try out the master-detail acceleration feature. I dragged an Order table from Data Sources and its related OrderDetail table to the form. I was able to hide columns in the Order datagrid (by setting zero widths), but not in the OrderDetail datagrid. Am I missing something
Thanks for helping.

DataGrid - 3 problems
Fran Garcia
I added these three lines to the end of menuItem1_Click and menuItem2_Click of the main form to dispose of the dialog object and to rebind the datagrid:
EditViewDialog.Dispose();
dataGrid1.DataSource = null;
dataGrid1.DataSource = productsBindingSource;
And miraculously, it worked.
As for my other problem (3), a simple rebinding will hide the columns (whose widths I have set to zero in the designer):
masterDataGrid.DataSource = null;
masterDataGrid.DataSource = masterBindingSource;
childDataGrid.DataSource = null;
childDataGrid.DataSource = fk_master_childBindingSource;
Seems that rebinding is the cure-all for most datagrid problems, at least for me. :)
bubixMister
Thanks for any insight.
mariascandella
CurrentBindingSource = bsource;
InitializeComponent();
CurrentBindingSource = bsource;
InitializeComponent();
in the beginnng of EditView constructor Works for me like this (with your other fix of course and a few typos corrected). Overall I'd say this sample needs some editing
Gusi
I tried printing the position of current in the EditView constructor:
CurrentBindingSource = bindingSource;
MessageBox.Show(CurrentBindingSource.Count + " " + CurrentBindingSource.IndexOf(CurrentBindingSource.Current));
InitializeComponent();
... and as expected of the problem, on the first "New", the index of Current is correct, but on the second "New", the index is zero.
TurboDoc