Custom Sort a column: Sort/Group/FilterMemberPath containing indexer expression

2 posts, 0 answers
  1. Bas
    Bas avatar
    1 posts
    Member since:
    Mar 2014

    Posted 08 May 2014 Link to this post

    I'm building a way to generate columns based on an IEnumerable inside a ViewModel bound to a single row. 
    When creating a cell element, the DataContext of that element is set to something based on a property path.

    Consider the following example:

    class Order {
           public List<OrderLine> Lines { get; }
    class OrderLine {
            public int Index { get; }
          public string Data { get; }
    • A GridViewRow would be bound to an Order object.
    • For each line in this example a column will be created.

    To achieve this, I created a custom column:

    public override FrameworkElement CreateCellElement(GridViewCell cell, object dataItem)
           // more code to create item etc.
               new Binding(DataMemberBindingPath) { Source = dataItem });

    The DataMemberBindingPath contains something like Lines[0] or Lines[1]. This works fine since the WPF data binding engine can handle this. When I try to define the SortMemberPath containing an Indexer, nothing happens and the expression does not seem to be parsed.

    Looking at the GridViewColumn source code, there is a method of interest:

    internal virtual Expression CreateSortKeyExpression(ParameterExpression parameterExpression, ExpressionBuilderOptions options)
            var builder = CreateBuilder(parameterExpression, this.EffectiveSortMemberType, this.EffectiveSortMemberPath, options);
            return builder.CreateMemberAccessExpression();

    However the method is Internal and I cannot override this to allow working with indexers.

    Is there any workaround available to override the sort behavior for a custom column?

  2. Dimitrina
    Dimitrina avatar
    3769 posts

    Posted 09 May 2014 Link to this post


    You can check the possibility to define your own generic SortDescriptor and add it to RadGridView.SortDescriptors colleciton. How do you consider this option?

    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
Back to Top