I am using wpftoolkit grid but the sorting does not work when click on the header columns to sort. This is what I am using
<ObjectDataProvider x:Key="OrdersObjectDataProvider"
ObjectType="{x:Type business:Orders}"
IsInitialLoadEnabled="False"
IsAsynchronous="False"
MethodName="GetOrdersNone">
</ObjectDataProvider>
DataGrid Grid.Row="1" Margin="6,37,0,4" Name="dataGridOrders"
CellStyle="{StaticResource DataGridCellStyle}"
AutoGenerateColumns="False"
SelectionUnit="Cell"
CanUserSortColumns="True"
ItemsSource="{Binding Source={StaticResource OrdersObjectDataProvider}}" >
private ObjectDataProvider _odp = new ObjectDataProvider();
_odp = this.FindResource( "OrdersObjectDataProvider" ) as ObjectDataProvider;
_odp.DataChanged += new EventHandler( odp_DataChanged );
_odp.Refresh();
private void odp_DataChanged( object sender, EventArgs e ) {
if (_odp.Error != null)
throw _odp.Error;
this.dataGridOrders.DataContext = _odp; }
I have posted a question in the codeplex group and this is what I got back
"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."
With windows forms we use SortedBindingList and something like this would work
Csla.SortedBindingList<Destination> sortedList =
new Csla.SortedBindingList<Destination>( destinations );
sortedList.ApplySort( "Short_nm", ListSortDirection.Ascending );
this.destinationsBindingSource.DataSource = sortedList;
How would you do something similar with WPF using CslaDataProvider or ObjectDataProvider?
Thanks
You could use something like this to wrap the list ... and support sorting --
var someCollection =
from someObject in someObjectList
select someObject;
DataGrid.ItemsSource = someCollection;
Unfortunately it isn't that simple. The result of a LINQ query is an IEnumerable<T>, which is the most basic collection type in .NET. That breaks all sorts of semantics, including auto-sorting, but also CSLA persistence.
CSLA 3.5-3.8 addresses this by changing the LINQ query to return a LinqBindingList<T> - but that implements IBindingList and is still not WPF-friendly.
CSLA 4 changes all collection base types to ObservableCollection<T>, so all CSLA collection types default to supporting WPF (and Siilverlight, ASP.NET Web Forms and ASP.NET MVC). There are now alternate base types for Windows Forms developers, because that's now the odd technology that requires IBindingList.
So the long-term answer is to move to CSLA 4. The short-term answer is really quite complex, since it requires that you wrap an IBindingList collection with ObservableCollection semantics. There are some blog posts out there about how to do this, but none of the answers are particularly good.
Microsoft really made life difficult when they decided that WPF would only provide partial support for IBindingList and/or that Windows Forms would provide absolutely no support for ObservableCollection...
Our current implementation (3.8.3) has an info list of read-only items. We initially had a linq filtered list bound to the grid …. and sorting worked. Then we changed the implementation to bind the grid directly to the list, and suddenly, sorting was disabled.
Great solution … nope, we’d rather use the ObservableCollection…. but for now, it’s a simple solution for a read-only list Yet, as you clearly point out, persistence and other benefits are removed in doing so.
Oh, you know why - I think the DataGrid detects that the source is a super-dumb list and wraps it in a CollectionViewSource or something. They specifically don't do that for an IBindingList.
Copyright (c) Marimer LLC