与ObjectListView自定义排序 [英] Custom Sorting with ObjectListView

查看:337
本文介绍了与ObjectListView自定义排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们说我有3列

ArticleNumber | OrderNumber | Status
 8080         | 123.456.789 | Delivered
 80           | 456.789.101 | Pending
 901          | 11.111.111  | Delivered

通过自动分拣,较小的文章编号,会去下更大的文章编号,所以它会无论是那种8080,80,901或901,80,8080,但我想,最小的数量会在上面。

With the Automatic sorting, the smaller article number would go under the bigger article number, so it would either sort 8080, 80, 901 or 901, 80, 8080 but I want that the smallest number would be on top.

在订单号码是相同的。

和地位是行不通的。对了,它只是当我按下的columnHeader排序ArticleNumber所以我想排序取决于文本的状态。

And Status wouldn't work. On, it just sorts the ArticleNumber when I press the ColumnHeader so I'd like to sort the Status depending on the text.

我想我需要一个CustomSorter该任务但我找不到如何使用它,我无法找到一个很好的例子,OLV的食谱并没有帮助我。

I think I need a CustomSorter for that task but I couldn't find how to use it and I couldn't find a good example, the cookbook of OLV didn't help me.

你有一个实例吗?我怎么可以这样做。

Do you have an Example for me how this could be done?

推荐答案

使用自定义分类器示例:

Example using a custom sorter:

MyOlv.CustomSorter = delegate(OLVColumn column, SortOrder order) {
    // check which column is about to be sorted and set your custom comparer
    if (column == ArticleNumber) {
        MyOlv.ListViewItemSorter = new ArticleNumberComparer(order);
    }
};          

class ArticleNumberComparer : IComparer {
    SortOrder _Order;

    public ArticleNumberComparer(SortOrder order) {
        _Order = order;
    }

    public int Compare(object x, object y) {
         // perform you desired comparison depending on the _Order
    }
}

请注意在比较X和Y()是类型的ListViewItem的。你可以看看关于如何访问底层模型对象,这

Note that x and y in Compare() are of type ListViewItem. You can take a look at this on how to access the underlying model objects.

这篇关于与ObjectListView自定义排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆