Sorting does not work with bunisess objects

Nov 28, 2008 at 4:55 PM
I have a business object that I am attaching to a grid. However, I can not sort it. It is using BindingList. Can we we make the grid sort?

Thanks
Dec 1, 2008 at 8:33 AM
Hi,

BindingList does not implementing sorting (or filtering), you can confirm this by testing the BindingList.SupportsSorting methods which returns false. When using a BindingList it is up to you to implement sorting.

BindingList is the old collection that is used for databinding. Within WPF you should use ObservableCollection which does implement sorting and will allow your grid to sort.

Regards,
Colin E.
--
http://wpfadventures.wordpress.com/ - my WPF blog
http://www.codeproject.com/KB/WPF/WPFDataGridExamples.aspx - WPF DataGrid Practical Examples
Dec 1, 2008 at 8:44 PM
Colin,
how can I implement sorting for IBindingList for the toolkit?

Thanks
Dec 2, 2008 at 7:54 AM
Hi,

You could inherit from BindingList and implement sort. See this forum post:

http://bytes.com/groups/net-c/754604-sort-bindinglist

However, if you go to all this effort - why not just use ObservableCollection ?

Regards,
Colin E.
--
http://wpfadventures.wordpress.com/ - my WPF blog
http://www.codeproject.com/KB/WPF/WPFDataGridExamples.aspx - WPF DataGrid Practical Examples
Dec 2, 2008 at 9:56 PM
How can I attach the sort view utility to ObjectDataProvider?

Are you going to support sorting for BindingList when you release the product?

Thanks
Dec 3, 2008 at 5:27 AM
Hi Colin,

 What georgio is trying to say (I think) and what I keep trying to find, is that ObservableCollection just can't do for us, because we are usign linq objects that have a AsBingingList() method and no AsObservableCollection method.

 Georgio

  Unfortunately for us there is little hope sorting will ever be supported on BindingList, you can take a look at http://www.codeplex.com/bindablelinq maybe it will help.

Regards,
Calin
Dec 3, 2008 at 2:43 PM
We are using a framework that binding is based on BindingList. I have tried out some vendor products (telerik)
and sorting works out of the box without any extra code. They must do something internally. Can you do something similar?

Thanks
Dec 11, 2008 at 9:49 AM
There's a good article here about how to get a CollectionViewSource to do the sorting on your Binding list here:

http://wpfmentor.blogspot.com/2008/12/observable-collections-independent-of.html
Dec 12, 2008 at 6:48 PM
I do not seem to get it to work. I do not get any error but the grid does not display the results. Any ideas? This is what I have.

 

<local:ExtendedCollectionViewSource x:Key="cvs" Source="{Binding}">

 

 

<local:ExtendedCollectionViewSource.SortDescriptions>

 

 

<ComponentModel:SortDescription Direction="Descending"/>

 

 

</local:ExtendedCollectionViewSource.SortDescriptions>

 

 

</local:ExtendedCollectionViewSource>

 







 

<dataGridView:DataGrid Grid.Row="1" Margin="6,39,31,9"

 

 

Name="dataGridOrders"

 

 

AutoGenerateColumns="False"

 

 

SelectionUnit="Cell"

 

 

ItemsSource="{Binding Source={StaticResource cvs}}"

 



//c#

orders = Pts.OrderQuery.Library.

Orders.GetOrdersNone();

 

dataGridOrders.DataContext = orders;