Sorting FilterableCollectionBase

Sorting FilterableCollectionBase

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


pmaher posted on Monday, July 03, 2006

I've created a reusable UI control that encapsulates a DataGridView and allows filtering with the FilterableCollectionBase.

I wanted to make the class generic in order to specify a RootList for the rows and a Child type to reflect upon for enabling features of the control. I ran into the problem that VisualStudio2005 will not allow me to put a control implemented as a generic class into the ToolBox. To get around this problem I created a "generic method" so the UI developer can still specify a list and child type.

public void SetDataSource<T>(IList<T> list, Type type )

I can set the datasource to the full list or to a filtered list depending on user input through the control. The user can use the column headers to sort based on the column values. This works well for sorting 'OR' for filtering. The problem I've encountered is when the user filters the original list and then clicks the column header of the DataGridView to sort the filtered rows. The DataGridView throws an exception stating "DataGridView control cannot be sorted if it is bound to an IBindingList that does not support sorting."

It appears that the FilterableCollectionBase returns a collection that does not support sorting. It would seem that an easy solution would be to pass the filtered collection through SortedBindingList<T> to get a sortable collection before setting it to the datasource of the DataGridView. My problem here is that the type inference <T> is only valid within the generic method.

Is there a way to instantiate a SortedBindingList<T> with only a reference to the list?

Has anyone made FilterableCollectionBase sortable?

Has anyone else out there run into similar problems?

Any help would be appreciated.

Thanks,

Pat

RockfordLhotka replied on Tuesday, July 18, 2006

You might try the (not yet released) FilteredBindingList<> that is coming in version 2.1. The C# code is in cvs (www.lhotka.net/cslacvs) under the 2.1 branch.

pmaher replied on Wednesday, July 19, 2006

I went to www.lhotka.net/cslacvs but can't find a 2.1 branch

 

RockfordLhotka replied on Wednesday, July 19, 2006

First get into the csla20cs subfolder, then you can use the Sticky Tag combobox to choose the V2-1 branch.

RockfordLhotka replied on Wednesday, July 19, 2006

I should point out that you need several files - FilteredBindingList, IFilterable, FilterProvider and DefaultFilter.

markmconel replied on Friday, July 21, 2006

Maybe I'm lacking investigative skills, however, I'm unable to find the 2.1 branch in cvs. I was hoping to play around with and possibly finish the incomplete FilteredBindingList<>. Is this missing or am I blind? Thanks in advance.

markmconel replied on Friday, July 21, 2006

Sorry about this post. I am also lacking reading ability since I didn't read the entire thread before responding.

RockfordLhotka replied on Friday, July 21, 2006

For those interested, the VB version of FilteredBindingList is now in the V2-1 branch of cvs as well.

Copyright (c) Marimer LLC