对自动筛选内容进行排序 - XCeed WPF Datagrid

发布于 2024-12-16 12:40:27 字数 224 浏览 2 评论 0原文

我在应用程序中使用 Xceed WPF Datagrid。我已在其中一列上启用自动筛选,但内容未排序。我不知道是否有一个属性或其他东西,也许是一种样式,可以告诉它按字母顺序排序。有人有这方面的经验吗?

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

谢谢, 纳撒尼尔·D·霍尔科姆

I am using an Xceed WPF Datagrid in an app. I have enabled Autofilter on one of the columns, but the contents are not sorted. I can't figure out if there is a property or something, a style perhaps, to tell the thing to sort alphabetically. Has anyone had any experience with this?

Unfortunately, when I google search, or even search on Xceed's website, everything related to sorting is sorting the rows by clicking a column header. But I want the list of options in the autofilter dropdown to be sorted...

Thanks,
Nathaniel D. Holcomb

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

帥小哥 2024-12-23 12:40:27

您可以在代表您的列的 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" />

You can set the DistinctValuesSortComparer property on the ItemProperty that represents your column and do your custom sorting within the comparer.

I believe they have this set in their sample application.

For example:

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" />

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文