Custom sort with FastObjectListview is not working
Hey, I'm using the FastObjectListview and now I need to sort on 2 columns. So I tried using the example I found on the ObjectListview website but I can't get it to work.
class MyCustomSortingDataSource : FastVirtualListDataSource
{
override public void SortObjects(OLVColumn column, SortOrder order) {
// do some amazing sorting here
this.RebuildIndexMap(); // you must call this otherwise the control will not work properly
};
};
...
this.myFastObjectListView.DataS开发者_JAVA技巧ource = new MyCustomSortingDataSource(this.myFastObjectListView);
first of all I added:
using BrightIdeasSoftware;
but that namespace doesn't contain the FastVirtualListDataSource it contains a FastObjectListDataSource.
in the FastObjectListDataSource however there is no SortObjects method to override, there's a Sort method which I guess I should be overriding instead.
So this is what I got instead of the sample code:
class MyCustomSortingDataSource : FastObjectListDataSource
{
public MyCustomSortingDataSource(FastObjectListView listView)
: base(listView)
{
}
public override void Sort(OLVColumn column, SortOrder sortOrder)
{
base.Sort(column, sortOrder);
// do some amazing sorting here
// base.ObjectList.Sort(new ModelObjectComparer(this.olvGroupCln, SortOrder.Ascending, column, sortOrder));
this.RebuildIndexMap(); // you must call this otherwise the control will not work properly
}
}
I can't access the olvGroupCln which is the first column I need to sort on, after sorting that column I need to sort the column the user clicked on.
Some help would be gladly appreciated.
Thanks in advance.
That's always the problem with documentation -- it's never quite up to date. I'll fix the docs.
I guess you can't access your olvGroupCln
variable because it is on the form itself, and you need it within the sorter? Is that right?
Just give your custom sorter a property that holds the column you want to sort by. Whenever you set olvGroupCln
, set the property on your sorter too. Something like this
class MyCustomSortingDataSource : FastObjectListDataSource
{
public MyCustomSortingDataSource(FastObjectListView listView)
: base(listView) { }
public OLVColumn SortColumn {
get { return this.sortColumn; }
set { this.sortColumn = value; }
}
private OLVColumn sortColumn;
public override void Sort(OLVColumn column, SortOrder sortOrder)
{
if (sortOrder != SortOrder.None) {
ArrayList objects = (ArrayList)this.listView.Objects;
objects.Sort(new ModelObjectComparer(this.SortColumn, SortOrder.Ascending, column, sortOrder));
}
this.RebuildIndexMap();
}
}
精彩评论