1

I have a grid with (n) dynamically generated columns. One of the requirements is that a row only be shown in the grid if a non-null/non-zero value exists in one of the shown columns. I am using an Infragistics XamGrid, which has the option to use a row filter that will accept an expression as its filter criteria. I have bound the Key of my columns to MyObject properties.

I am trying to generate a chain of expressions based on which columns in my grid are shown. Here is some pseudo-code that shows an idea what I'm trying to accomplish

System.Linq.Expressions.Expression<Func<MyObject, bool>> expr = product =>
{
    foreach (var p in MyGrid.Columns.Where(co => co.DataType == typeof (decimal?) && co.Visibility == Visibility.Visible))
    {
        Expression<Func<MyObject, bool>> exprInner = lrnc => ((decimal?) lrnc.GetPropValue(p.Key)) != 0.0m;
        combined = System.Linq.Expressions.Expression.OrElse(combined.Body, exprInner.Body);
    }
};
2

1 Answer 1

0

Big thanks to hatchet and his link. I was able to dynamically combine expressions based on reflected properties to create a RowsFilter for my XamGrid.

private RowsFilter m_rowsFilter;

private void CreateFilter()
{
    CustomComparisonCondition c = new CustomComparisonCondition();

    var predicate = PredicateBuilder.False<LineRatingNodeComparison>();
    foreach (string colKey in MyXamGrid.Columns.Where(co => co.DataType == typeof (decimal?) && co.Visibility == Visibility.Visible).Select(co => co.Key))
    {
        string tempKey = colKey;
        predicate = predicate.Or(p => p.GetPropValue(tempKey) != null && (decimal?) p.GetPropValue(tempKey) != 0.0m);
    }
    c.Expression = predicate;

    //Add the RowsFilter to one column that always exists on the grid.
    m_rowsFilter = new RowsFilter(typeof (MyObject), MyXamGrid.Columns.DataColumns["Company"]);
    m_rowsFilter.Conditions.Add(c);
    MyXamGrid.FilteringSettings.RowFiltersCollection.Add(m_rowsFilter);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.