Filter with array of parameters

4 posts, 0 answers
  1. Roberto Wenzel
    Roberto Wenzel avatar
    41 posts
    Member since:
    Sep 2012

    Posted 02 Sep 2008 Link to this post

    Hi, I would like to filter my GridView programmatically.
    How do I use an array of search paramters.
    Let's say I have a text array with 3 or for text strings and I want to filter one or more columns for these strings.
    The result should be all rows where one ore more of my search strings is contained.
    Thank you for a code snippet in vb.
    Cheers Roberto
  2. Jordan
    Admin
    Jordan avatar
    547 posts

    Posted 03 Sep 2008 Link to this post

    Hi Roberto Wenzel,

    You can filter the values for a column in the way that you want by adding filter predicates for each value like:
     
    string[] filterParams = new string[] { "Ber""Ca" }; 
                FilterExpression filter = new FilterExpression(); 
                foreach (string filterParam in filterParams) 
                { 
                    filter.Predicates.Add(FilterExpression.BinaryOperation.OR, GridKnownFunction.StartsWith, filterParam); 
                } 
     
                this.radGridView1.Columns["City"].Filter = filter; 

    In a similar way you can add filter expressions for all the columns you need.

    To show all rows where one or more columns satisfy the filter expression for that column you can combine the filter expressions with the OR operator like:

    filter.BinaryOperator = FilterExpression.BinaryOperation.OR;

    Kind regards,
    Jordan
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Roberto Wenzel
    Roberto Wenzel avatar
    41 posts
    Member since:
    Sep 2012

    Posted 03 Sep 2008 Link to this post

    Hello and thank you for the code example. But I need some more help implementing that code.
    I am trying to to filter two columns with an OR operation.
    Let's assume the following GridView:

                Col1     Col2
    Row1     x         x
    Row2     y         z

    When my search array contains ("x", "y") I expect as result set Row1 and Row2.

    Your code works fine when filtering/searching only one column.
    For filtering two columns I tried following code, which does not work properly:

    Dim fe As New FilterExpression
    Dim fe1 As New FilterExpression
    Dim i As Integer
            If ary.Length > 0 Then
                For i = 0 To UBound(ary)
                    fe.Predicates.Add(FilterExpression.BinaryOperation.OR, GridKnownFunction.Contains, ary(i))
                    fe.Parameters.Add(GridFilterCellElement.ParameterName, ary(i))
                    fe1.Predicates.Add(FilterExpression.BinaryOperation.OR, GridKnownFunction.Contains, ary(i))
                    fe1.Parameters.Add(GridFilterCellElement.ParameterName, ary(i))
                Next

            End If

            Me.gvMessages.Columns("ResolvedValue").Filter = fe
            Me.gvMessages.Columns("MessageValue").Filter = fe1

    The result for search array ("x","y") is just Row1, because value "x" is in both columns.
    fe and fe1 seem to be connected with an AND operation. What I need is an OR operation.
    Maybe it is not possible to do what I like by default. In that case I need another approach, like iterating through all cells and highlight the found text or mark the cell with another background color or something like that.
    Maybe you have another idea?
    Cheers Roberto

  5. Jordan
    Admin
    Jordan avatar
    547 posts

    Posted 05 Sep 2008 Link to this post

    Hi Roberto Wenzel,

    Looking at your code it seems that the predicates are OK. However it is not clear how you create the filter expressions.

    Did you try setting the binary operator of the second filter expression to OR like:
    fe1.BinaryOperator = FilterExpression.BinaryOperation.OR;

    If that does not work I will need the code that creates the filter expressions, so that I can reproduce your complete scenario locally.

    Best wishes,
    Jordan
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Back to Top