EditLevel Error with Linq Sort

EditLevel Error with Linq Sort

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


Topher posted on Wednesday, May 20, 2009

WinForms
CSLA 3.6.2
.NET 3.5 SP2

I've been trying to sort a child collection on a column header click in a DataGridView using Linq. I can get the the collection to sort, but I'm unable to edit the child collection due to an EditLevel error. The child collection edits fine if I don't try to apply sorting.

I have a pretty simple object graph: Parent -> ChildCollection -> Child. The parent and child inherit from BusinessBase, the ChildCollection from BusinessListBase. I'm using a CslaActionExtender control to handle the windows databinding. The form has various controls which have the following pertinent settings:

On form load I'm populating and sorting my collection like this:

Dim _sortDirection As SortOrder = SortOrder.Ascending

Private Sub FillForm()
End Sub


And I'm handling the ColumnHeaderMouseClick event to enable sorting like this:

Private Sub ChildCollectionDGV_ColumnHeaderMouseClick(...) Handles ChildCollectionDGV.ColumnHeaderMouseClick
End Sub


I've seen Linq sort examples in the other forums, but I feel like I'm missing something. Can someone point me in the right direction so I can sort and edit the child collection?

Thanks!
Topher

JonnyBee replied on Sunday, June 07, 2009

Hi,

I prefer to use SortedBindingList and FilteredBindingList when programming for WindowsForms.

Unbind/Rebind of bindingsources are quite "touchy" (tpo make sure you exit edit mode properly, calling either ApplyEdit og CancelEdit before unbind)

/jonny

RockfordLhotka replied on Sunday, June 07, 2009

The problem is that Windows Forms pre-dates LINQ, and they really aren't a great match.

While you can write a bunch of code to coerce LINQ to work with Windows Forms (and people do this), I agree that it is better to use technologies and solutions geared toward Windows Forms.

SortedBindingList and FilteredBindingList require FAR less code and naturally integrate with Windows Forms in ways LINQ probably never will (because Microsoft has quit updating Windows Forms in any meaningful way).

Copyright (c) Marimer LLC