【问题标题】:Sorting Columns AlphaNumerically in LISTVIEW in WPF在 WPF 的 LISTVIEW 中按字母数字对列进行排序
【发布时间】:2013-01-31 10:18:51
【问题描述】:

我们有 WPF 应用程序,其中我们是 ListView in One form, 我们想按字母数字顺序订购商品。

当我们对列进行排序时,它需要对字母数字 EG 进行排序

AW1 AW2 AW3

目前正在排序

AW1 AW100 AW2 AW200

那么需要改变什么?

 if (lastDirection == ListSortDirection.Ascending)
                    {
                        direction = ListSortDirection.Descending;
                    }
                    else
                    {
                        direction = ListSortDirection.Ascending;
                    }

还有

   // get the sort property name from the column's information.
                string sortPropertyName = sortableGridViewColumn.SortPropertyName;

                // Sort the data.
                Sort(sortPropertyName, direction);

这样的排序函数,

private void Sort(string sortBy, ListSortDirection direction)
    {
        lastDirection = direction;
        ICollectionView dataView = CollectionViewSource.GetDefaultView(this.ItemsSource);

        dataView.SortDescriptions.Clear();
        SortDescription sd = new SortDescription(sortBy, direction);

        dataView.SortDescriptions.Add(sd);
        dataView.Refresh();
    }

【问题讨论】:

  • 我不知道如何检查字母数字,请帮助。

标签: wpf wpf-controls wpfdatagrid wpftoolkit


【解决方案1】:

字符串比较是从左到右逐个字符进行的。因此,如果您将列名更改为 AW001、AW100、AW002、AW200,您的排序将正常工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-11-09
    • 1970-01-01
    • 2012-09-14
    • 2013-05-01
    • 2015-04-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多