CSLA collections and binding/sorting on child property

CSLA collections and binding/sorting on child property

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

Goran posted on Monday, March 28, 2011

Do CSLA collections support binding to child properties? Example, I need to return a collection of Invoices, including information about each Invoice Customer, and I need to bind this collection to a grid (ex DataGridView), which will display information from both Invoice and Customer entities (ex DataPropertyName = "Customer.Name").

And while grid is bound to this collection, I need to be able to sort on each column. Is this possible?



RockfordLhotka replied on Monday, March 28, 2011

This depends on the data binding technology, not really on CSLA.

CSLA collections are just .NET collections with the .NET binding interfaces implemented. The same with CSLA objects.

XAML binding can drill down to a child object. I don't think Windows Forms or Web Forms could do that.

Goran replied on Tuesday, March 29, 2011

Well, since we cant change how windows forms data binding works, then only other way is to extended our collections with custom PropertyDescriptors and custom TypeDescriptors. I was able to extend sortable collection to support binding to child properties, but I am busting my head how to create DynamicMethod delegate to support comparing on nested properties. Crying

JonnyBee replied on Wednesday, March 30, 2011

The simple solution is to flatten the hierarchy and have just one list with properties (no hierarchy). You shouldn't care too much about entities in your list and rather view it a one list with properties.

That way - Windows forms databinding will work just fine and you can sort on any field - just wrap your list with SortedBindingList in your form.



Copyright (c) Marimer LLC