Problem Binding a BusinessListBase to DataGridView on WinForms

Problem Binding a BusinessListBase to DataGridView on WinForms

Old forum URL: forums.lhotka.net/forums/t/11454.aspx


foxhard posted on Wednesday, July 04, 2012

Hi,

I need some help with EditableRootListBase class binding issue. I have EmployeeAccountList binded to  DataGridView used on a Windows Forms. Then When I change some data and try save then I get an exception: {"Edit level mismatch in AcceptChanges"}

I guess the problem is with the binding, because when I try the same using DevExpress GridControl, then nothing appear and the save is successfully.

I have written a test for try it, you can download from here:  http://ge.tt/7w8GW2K/v/0?c

The solution is in VS2010. written in C# and it use CSLA 3.8.4.

The CSLA.dll is include in the folder.

Regards,

JonnyBee replied on Wednesday, July 04, 2012

Hi,

You must understand the concept of Bind and Unbind business object and UI.

IE: You cannot call Save on an object that is databound and sequence of Bind/Unbind is also important to get right. 

I strongly suggest that you look at the BindingSourceExtensions in CslaContrib:
http://cslacontrib.codeplex.com/SourceControl/changeset/view/98444#1623433

IE: Unbind befor call to Save and then rebind before you can show a message dialog (as the DataGridView cannot get its items to show in the UI).

My blog post here about the sequence: http://jonnybekkum.wordpress.com/2009/10/20/forms-databinding-the-magic-sequence-of-binduiunbindui/

I also recommend these documents for Windows Forms:
DataBindingFAQ
DataGridViewFAQ

See attached zip file for updated solution.

foxhard replied on Wednesday, July 04, 2012

Thanks Jonny, now it looks great.

Copyright (c) Marimer LLC