User (Old forums)MemberFebruary 5, 2007 at 12:37 pmPost count: 23064
According to the information in the documentation, sorting is enabled by default and clicking a column header will cause the grid to sort by that column. Unfortunately, this doesn’t seem to be working for me.
I am binding to a generic collection that inherits from BindingList<T> and ITypedList and have the AutoCreateColumns property set to true. I am using the following code to bind the grid:
RootDocumentCollection documents = ClientContext.Current.ExecuteQuery(query);
if (documents.Count > 0)
Binding bind = new Binding();
bind.Source = documents;
this.ActionTestDataGrid.DataContext = documents;
All of this seems to work flawlessly and I am able to display the same data as I would see binding to a normal DataGridView in Windows Forms.
I was hoping this was all I would need to do. I am able to group by columns properly and all of the column headers are displayed corectly.
Imported from legacy forums. Posted by Scott (had 3308 views)Xceed SupportMemberFebruary 5, 2007 at 3:52 pmPost count: 5658
This is because BindingList<T>.SupportsSorting always returns “false” (through the SupportsSortingCore property).
You can try to encapsulate the collection in a ListCollectionView instead:
Binding bind = new Binding();
bind.Source = new ListCollectionView( documents );
But since ListCollectionView does not implement IBindingList, insertion would not be supported.
An alternative would be to override SupportsSortingCore and ApplySortCore from the BindingList<T> class and provide your own sorting logic (you can look into Array.Sort(), which can sort an array based on a comparer ).
In the mean time, we’re going to look into this a little more, since we are surprised that no implementation of IBindingList except DataView implements sorting.
We are going to follow-up in this thread whenever we find something.
Imported from legacy forums. Posted by Marcus [Xceed] (had 376 views)Xceed SupportMemberFebruary 5, 2007 at 4:27 pmPost count: 5658
After performing further verification, I have to admit I was wrong…
If you encapsulate your BindingList<T> implementation into a ListCollectionView, we still detect that the underlying data collection is a IBindingList and use it.
Therefore, all you need to do is as described above…
Imported from legacy forums. Posted by Marcus [Xceed] (had 390 views)User (Old forums)MemberFebruary 5, 2007 at 4:33 pmPost count: 23064
Excellent news. Your follow up post couldn’t have been timed any better. I was just getting ready to start discussing the plan for implementing the custom sorting and overriding SupportsSortingCore and ApplySortCore with the developer responsible for the collection.
I made the changes you described about encapsulating the collection in a ListViewCollection and the sorting is working properly.
Imported from legacy forums. Posted by Scott (had 3484 views)User (Old forums)MemberJune 30, 2008 at 5:57 amPost count: 23064
I also use IBindingList (I override BindingList<T>) and return true for SupportsSortingCore. The method ApplySortCore is not called like this. I found the solution in Beatriz Costa’s blog comment (http://www.beacosta.com/blog/?p=24). It appears that we must also implement ITypedList. I tryed it and ApplySortCore is called (in this method I call Array.Sort with my own comparator). Like this there is no need to wrap the IBindingList with the ListCollectionView (didn’t try if it also works that way).
PS: the normal sorting way (reflection) does not work in my case because my data objects are not strongly typed.
Imported from legacy forums. Posted by ステファン (had 1266 views)
- You must be logged in to reply to this topic.