HELP! Cannot enter datagridview using BBS on new record without erroring on rentrant call to...


Author
Message
Charles R Hankey
Charles R Hankey
Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)
Group: Forum Members
Posts: 524, Visits: 30K
I have a simple DGV using as a datasource a BBS connected to a childbo. Relationships all setup properly. Parent filters children. All data is loaded in parentform loading.



Starting with empty data in all tables.



I have tried setting Setdirtyonedit of the childbo instance to false and to true.



I can create a new parent, but on entering any grid I get the following error.



I know I'm missing something very basic here but as I have a dozen of these grids on my form this is a showstopper.



Would really appreciate any suggestions as to what I should be looking at and just what the tricks are to getting a datagridview and a bbs to play nice. For some reason I thought I had this all working and it does seem to not error if the parent isn't new, but on a new parent - BOOM



InvalidOperationException

Operation is not valid because it results in a reentrant call to the SetCurrentCellAddressCore function.



Source : System.Windows.Forms



Stack Trace:

at System.Windows.Forms.DataGridView.SetCurrentCellAddressCore(Int32 columnIndex, Int32 rowIndex, Boolean setAnchorCellAddress, Boolean validateCurrentCell, Boolean throughMouseClick)

at System.Windows.Forms.DataGridView.DataGridViewDataConnection.MatchCurrencyManagerPosition(Boolean scrollIntoView, Boolean clearSelection)

at System.Windows.Forms.DataGridView.DataGridViewDataConnection.ProcessListChanged(ListChangedEventArgs e)

at System.Windows.Forms.DataGridView.DataGridViewDataConnection.currencyManager_ListChanged(Object sender, ListChangedEventArgs e)

at System.Windows.Forms.CurrencyManager.OnListChanged(ListChangedEventArgs e)

at System.Windows.Forms.CurrencyManager.List_ListChanged(Object sender, ListChangedEventArgs e)

at System.ComponentModel.ListChangedEventHandler.Invoke(Object sender, ListChangedEventArgs e)

at MicroFour.StrataFrame.Business.BusinessBindingSource.OnListChanged(ListChangedEventArgs e)

at MicroFour.StrataFrame.Business.BusinessBindingSource.BusinessObject_IsDirtyChanged(Object sender, EventArgs e)

at MicroFour.StrataFrame.Business.BusinessLayer.raise_IsDirtyChanged(Object sender, EventArgs e)

at MicroFour.StrataFrame.Business.BusinessLayer.OnIsDirtyChanged(Boolean DirtyShouldBe)

at MicroFour.StrataFrame.Business.BusinessLayer.SetEditingState(BusinessEditingState EditState, Boolean RefreshControls)

at MicroFour.StrataFrame.Business.BusinessLayer.SetEditingState(BusinessEditingState EditState)

at MicroFour.StrataFrame.Business.BusinessLayer.Add(Boolean CheckSecurity)

at MicroFour.StrataFrame.Business.BusinessBindingSource.IBindingListView_AddNew()

at System.Windows.Forms.CurrencyManager.AddNew()

at System.Windows.Forms.DataGridView.DataGridViewDataConnection.AddNew()

at System.Windows.Forms.DataGridView.DataGridViewDataConnection.OnNewRowNeeded()

at System.Windows.Forms.DataGridView.OnRowEnter(DataGridViewCell& dataGridViewCell, Int32 columnIndex, Int32 rowIndex, Boolean canCreateNewRow, Boolean validationFailureOccurred)

at System.Windows.Forms.DataGridView.OnCellMouseDown(HitTestInfo hti, Boolean isShiftDown, Boolean isControlDown)

at System.Windows.Forms.DataGridView.OnCellMouseDown(DataGridViewCellMouseEventArgs e)

at System.Windows.Forms.DataGridView.OnMouseDown(MouseEventArgs e)

at System.Windows.Forms.Control.WmMouseDown(Message& m, MouseButtons button, Int32 clicks)

at System.Windows.Forms.Control.WndProc(Message& m)

at System.Windows.Forms.DataGridView.WndProc(Message& m)

at System.Windows.Forms.Control.ControlNativewindow.OnMessage(Message& m)

at System.Windows.Forms.Control.ControlNativewindow.WndProc(Message& m)

at System.Windows.Forms.Nativewindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Charles R Hankey
Charles R Hankey
Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)
Group: Forum Members
Posts: 524, Visits: 30K
If I save the parent before entering any child grid, i do not get the error in Edit mode.
Charles R Hankey
Charles R Hankey
Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)
Group: Forum Members
Posts: 524, Visits: 30K
I've reproduced this in a sample app.  The issue (at least the first one) is creating a new customer and then without saving entering the grid to add a new sale in the datagridview.

The data retrieval is done with a sproc that will be created by the DDT package.

For anybody that does not have the DDT I am also attaching the scripts to create Gridtest.mdf and the two sprocs

TIA

Attachments
GridTest.zip (127 views, 184.00 KB)
Gridtest.pkg (120 views, 14.00 KB)
Charles R Hankey
Charles R Hankey
Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)
Group: Forum Members
Posts: 524, Visits: 30K
Second problem in this sample :

On new the grid doesn't clear until the parent is saved.  Calling dgvSales.refresh() or .refreshedit() in the Afteraddnew of the CustomersBO seems to have no effect, but as soon as new customer is saved the grid shows the empty child grid. 

Tried setting SalesBO1 to Include in Add bu that isn't the answer either.

Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi Charles,



Also in your scripts you forgot to include the table scripts for Customers and Sales.



I have not worked with data grid, I use the list view for this kind of data entry, but I will check it out to see if I can help dig out this problem.

Edhy Rijo

Charles R Hankey
Charles R Hankey
Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)
Group: Forum Members
Posts: 524, Visits: 30K
The probem seems to be that in AfterAddNew the bbsSales still has as _Businessobjectcurrentview the set of records based on the parent before the add.  Remember, the autofilter is on.  Perhaps the autofilter match current row doesn't play well with the BBS? 

If I add the line

me.SalesBO1.filter = "fk_Customers = -1"

it solves the problem for existing data but blows up when both tables are empty.

Edhy - here's the scripts for creating tables (sorry, thought the generated database script did that - should have checked it - I use DDT all the time so I'm script stupid )

Attachments
Create tables.zip (112 views, 946 bytes)
Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Do not use the BO.autofilter it is not safe, I don't remember details but search the forum for more info.



In the CustomerBO1.Navigated add the this code below Me.dgvSales.Refresh() and try.



Me.SalesBO1.FillByParentPrimaryKey(Me.CustomersBO1.pk_Customers)

Edhy Rijo

Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Charles,



Forgot to mention, remove all the code from the SalesBO1.ParentFormLoading().



I believe the problem was that the BO.AutoFilter option was filtering the data and causing some sort of thread invoke error. It is always better for you to handle your own filters.

Edhy Rijo

Charles R Hankey
Charles R Hankey
Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)
Group: Forum Members
Posts: 524, Visits: 30K
Thanks for that suggestion. I hadn't really used the autofilter before but I liked the idea of not making a trip to the server on every navigate. Perhaps I could still pull all the data and then set filters manually.



I any case this does confirm that the combination of autofilter and BBS is the problem .



Perhaps Trent can confirm?



I'll search the forum for references to this problem.



When get the sample working reliably I'll post it in the contributed samples so somebody else won't have to go through the day I've had w00t



Charles R Hankey
Charles R Hankey
Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)
Group: Forum Members
Posts: 524, Visits: 30K
The suggestion to search was a good one !

I think i may have this solved by putting the line

me.customersBO1.FilterChildrecords()

in the afteraddnew. 

Fixes the problem in adding on empty data tables and in clearing existing child data on adding a new with exisitng data

So far so good.  I'll try it in my big app and if it tests out I'll post the sample with comments for anybody else who might want to do this.

BigGrin

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search