排序Autofilter内容 - XCeed WPF Datagrid

时间:2011-11-18 16:24:33

标签: wpf xceed-datagrid autofilter

我在应用中使用Xceed WPF Datagrid。我已在其中一列上启用了Autofilter,但内容未排序。我无法弄清楚是否有某个属性或某种东西,或许是一种风格,可以按字母顺序排序。有没有人有这方面的经验?

不幸的是,当我谷歌搜索,甚至搜索Xceed的网站时,与排序相关的所有内容都是通过单击列标题对行进行排序。但是我希望autofilter下拉列表中的选项列表能够排序......

谢谢, Nathaniel D. Holcomb

1 个答案:

答案 0 :(得分:1)

您可以在代表您的列的ItemProperty上设置DistinctValuesSortComparer属性,并在比较器中进行自定义排序。

我相信他们在示例应用程序中有这个设置。

例如:

C#

public class MonthNamesDistinctValuesSortComparer : IComparer
  {
    public MonthNamesDistinctValuesSortComparer()
    {
      for( int i = 0; i < DateTimeFormatInfo.CurrentInfo.MonthNames.Length; i++ )
      {
        string monthName = DateTimeFormatInfo.CurrentInfo.MonthNames[ i ];
        m_monthNameToIndex.Add( monthName, i );
      }
    }

    #region IComparer Members

    public int Compare( object x, object y )
    {
      string xMonth = x as string;
      string yMonth = y as string;

      if( ( xMonth != null ) && ( yMonth != null ) )
      {
        int xIndex = m_monthNameToIndex[ xMonth ];
        int yIndex = m_monthNameToIndex[ yMonth ];

        if( xIndex < yIndex )
        {
          return -1;
        }
        else if( xIndex == yIndex )
        {
          return 0;
        }
        else
        {
          return 1;
        }
      }

      // Unable to compare, return 0 (equals)
      return 0;
    }

    #endregion

    private Dictionary<string, int> m_monthNameToIndex = new Dictionary<string, int>();
  }

XAML

<local:MonthNamesDistinctValuesSortComparer x:Key="monthNamesDistinctValuesSortComparer" />
<xcdg:DataGridItemProperty Name="ShippedDate"
                                          Title="Shipped Date"
                                          DistinctValuesSortComparer="{StaticResource monthNamesDistinctValuesSortComparer}"
                                          QueryDistinctValue="OnShippedDateQueryDistinctValue" />