dataGridView and sorting

dataGridView and sorting

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


al4114al posted on Friday, September 09, 2011

Hi everyone!

I'm using Csla 3.6.1 for my project.  I have a form that contains, among other things, a dataGridView I'll call xyz. To provide sorting, I have:

      xyz.DataSource = new SortedBindingList<item>(items);

The 'parent' abc form is bound as:

     abc.DataSource = _abc_thingy;

When column headers are clicked, sorting works as I hoped.  However, when hitting any of OK, Apply, Cancel or Close buttons, the whole application shuts down with no kind of message.  If I only go into the form and, without sorting, use any of the four buttons, I get normal behavior.

I'm pouring through the forum for ideas on this, but so far I haven't hit on anything.

Has anyone dealt with this problem?  If my continued putzing with the code solves this, I'll post the solution so someone else may use it.

 

Thanks for any help.

JonnyBee replied on Saturday, September 10, 2011

Hi,

I assume you are using Windows Forms?

I'd start by grabbing the latest versions of SortedBindingList and FileteredBindingList. There's been a few bugfixes to these lists so that you should make sure to have updated versions. These were bugs where ListChanged event was raised with an erronous Index og the item in the list (added, removed or changed) - when the list is sorted.

In WinForms I always recommend to use BindingSource component between the data objects and UI components. The BindingSource will allow you to hook into databinding errors to find out what exceptions are beeing thrown.

Look at theBindingSource.DataError event.
http://msdn.microsoft.com/en-us/library/system.windows.forms.bindingsource.dataerror.aspx

al4114al replied on Saturday, September 10, 2011

Hi Jonny -

Thank you for the quick reply.  I'll follow up on what you suggest.

al4114al replied on Monday, September 12, 2011

Hi Jonny -

As you suggested, I got the latest SortedBindingList.  I'm sure it will help me avoid future problems.

As it turned out, I didn't have a binding issue.  It seems that having forms use WinPart rather than Form can cause some types of error messages to not display.  My real problem is yet another instance of someone encountering "Edit level mismatch in CopyState".  Blecchh!

Now I am looking, both in the forum and at-large for anything about what the heck sort actually does to a dataGridView in terms of its edit level, so I can 'fake it out' or whatever.

If anyone can assert that upgrading to newer MS technologies will eliminate this madness, I could move up my upgrade plans to the immediate.  Failing in that, can someone offer either a known workaround, or a source of emotional stability help?  Either would be much appreciated.

Of course, if I can find my own solution to my edition of the problem, I'll post it.

Thanks to all who read this.

JonnyBee replied on Monday, September 12, 2011

These problems is probably fixed in a newer version of Csla.

It's related to the implementation of IEditableObject (BeginEdit/CancelEdit/EndEdit) in BusinessBase.

BusinessBase must keep track of whether IEditableObject.BeginEdit is already called and only honor the first call on the interface method.
This will enable you to use multiple binding sources (or  datagrids) on the same list/BO and avoid Edit Level mismatch.

Fixed in CSLA 4.0.x and you can look at the implementation in Csla.Core.BusinessBase of the IEditableObject interface and update these in your version. 

More details on the issue can be found here: http://www.lhotka.net/cslabugs/edit_bug.aspx?id=241

al4114al replied on Monday, September 12, 2011

Again, Jonny, thank you so much.

I'll dig into this.

Copyright (c) Marimer LLC