RadGridView - Filter Programatically

14 posts, 0 answers
  1. Bob
    Bob avatar
    9 posts
    Member since:
    Apr 2009

    Posted 03 Aug 2009 Link to this post

    I am using Q1 2008 Winforms

    I have looked at the other threads relating to this issue and they either dead end or reference methods/properties that are no longer available.

    I populated my RadGridView via DataSet
    I also populate numerous comboboxes with that same Dataset.

    I desire to select to select a combobox, choose an item within the combobox and on selectedindex changed filter the RadGridView accordingly.
    I also want to be able to select as many comboboxes as i'd like to continuously filter down the RadGridView.

    I cannot seem to find valid code for setting the filter expression programatically.

    Please advise.

  2. Boryana
    Admin
    Boryana avatar
    329 posts
    Member since:
    Sep 2012

    Posted 04 Aug 2009 Link to this post

    Hello Bob,

    Thank you for contacting us. In order to achieve the desired behavior you should handle the SelectedIndexChanged event and set a new filter expression to the column that corresponds to the current RadComboBox. If you have encountered any issues assigning filter expressions please, refer to the this article. It provides examples how to set filter expressions programmatically and also how to assign filters for multiple columns. Please, note that in order to apply a filter the EnableFiltering property of RadGridView should be set to true. Another important point in your case is that you should bind each RadComboBox to a different BindingSource. I hope this is helpful. If you have further question, do not hesitate to contact me back.

    Best wishes,
    Boryana
    the Telerik team


    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.

  3. Bob
    Bob avatar
    9 posts
    Member since:
    Apr 2009

    Posted 04 Aug 2009 Link to this post

    Boryana,

    Thank you for your reply I had found the article that you reference in your reply and I am in the process of implementing.

    I did take your advice and I actually populate the combobox based on the contents of the radgridview:

    Dim OrderNumbers As String = String.Empty

            For Each rowinfo As GridViewRowInfo In dgvDetails.Rows
                With cboOrderNumbers
                    Dim newValue As String = Convert.ToInt16(rowinfo.Cells(10).Value).ToString

                    If Not OrderNumbers.Contains(newValue) Then
                        .Items.Add(New RadComboBoxItem(newValue))
                        OrderNumbers += newValue + ","
                    End If

                    'if we don't do this then the value is null
                    rowinfo.Cells(0).Value = False
                End With
            Next

    I set .EnableFiltering to False because I didn't want the filter row to be visible but of course then the programatic filtering didn't work.

    Is there a way to .EnableFiltering and keep the Filter Row not visible?

    Thank you in advance for your response.

    Bob

  4. Boryana
    Admin
    Boryana avatar
    329 posts
    Member since:
    Sep 2012

    Posted 04 Aug 2009 Link to this post

    Hello Bob,

    Please, add the following snippet to your code:

    Me.radGridView1.EnableFiltering = True 
    Me.radGridView1.MasterGridViewTemplate.ShowFilteringRow = False 

    I hope this helps. If you have further questions, please contact me back.

    All the best,
    Boryana
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.

  5. Bob
    Bob avatar
    9 posts
    Member since:
    Apr 2009

    Posted 04 Aug 2009 Link to this post

    Thank you for your quick response.

    That is what I was looking for. I'm still new to the Telerik controls so I don't always no where to find what I'm looking for.

    It does seem however that I can do just about anything I want if I can find it - or you guys tell me where it is :)

    One final question/observation...

    Is this the correct and/or most efficient way to clear a specific filter?

    filter.Predicates.Clear()
    filter.Parameters.Clear()
    Me.RagGridView1.Columns(columnName).Filter = filter

    Is this the correct and/or most efficient way to clear "ALL" filters.

    Me.RadGridView1.MasterGridViewTemplate.FilterExpressions.Clear()

  6. Boryana
    Admin
    Boryana avatar
    329 posts
    Member since:
    Sep 2012

    Posted 05 Aug 2009 Link to this post

    Hi Bob,

    I believe that the best way to clear the filter expression of RadGridView is:

    Me.radGridView1.MasterGridViewTemplate.FilterExpressions.Clear() 

    Kind regards,
    Boryana
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.

  7. Rick Petersen
    Rick Petersen avatar
    13 posts
    Member since:
    Feb 2009

    Posted 06 Aug 2009 Link to this post

    Boryana,

    Your responses to this question have been very helpful to me despite it not being my original post, but I have run into another roadblock.

    I am finding that (and correct me if I'm wrong) the GridKnownFunction.EqualTo function cannot be used to compare two strings.

    In my case I have a grid with many columns of different types.  On one of the columns which I have explicitly set the columns datatype to : typeof(string), and which contains values coming from a query typed as VARCHAR(10), I have an EqualTo filter.  I can take a value from one of the cells in that column, paste it into the EqualTo filter box and I get no results.  I change it to 'BeginsWith' and I get no results.  I change it to 'EndsWith' and I get what would be expected.  In this example, below are the values being used and the reasons it won't work for me if this is the only way:

    A value from that column:  "        11"  (without the quotes)
    With that value in the filter bar and EqualTo set as the function, I get 0 records.
    With that value in the filter bar and StartsWith set as the function, I get 0 records.
    With that value in the filter bar and EndsWith set as the function, I get something like 50 records.  But it isn't strings that end with "        11" but rather strings that end with "11".  I get the following results:

            11
            11
         20011
         67411
         67511
    ...
         70011

    etc.

    That seems to tell me that the preceding spaces in the filter string are ignored but preceding spaces in the rows being compared to the filter are not; that is the only behavior that can explain why it would match EndsWith but not BeginsWith or EqualTo.  Is there a way to make the filtering NOT ignore those preceeding spaces?  I REALLY want to set the filter to EqualTo, pass in "        11" and get the rows that have that value EqualTo "        11".

  8. Rick Petersen
    Rick Petersen avatar
    13 posts
    Member since:
    Feb 2009

    Posted 06 Aug 2009 Link to this post

    Verified, and work-around... I ltrim'd all the strings coming in in my query and now I can use the EqualTo to compare them.  I really think, unless there's a compelling argument opposed to it, the best way to treat a string typed into your filter bar is to leave it alone and not assume any stripping/trimming is needed.  Let your users handle the strings as needed.

    Work-around accomplished, but if there is a way to disable this behavior in the tool myself that would be nice.

  9. Boryana
    Admin
    Boryana avatar
    329 posts
    Member since:
    Sep 2012

    Posted 07 Aug 2009 Link to this post

    Hello Rick Petersen,

    Thank you for the detailed explanation of your issue. Unfortunately, what you are experiencing is the default behavior of RadGridView. Your suggestion that there should not be any assumed trimming seems convincing and is highly appreciated by our team. Your case made us reconsider the behavior of RadGridView for future releases. Thank you once again for your feedback. It comes out that at the moment the workaround that you have found yourself is the only one we can suggest. If you encounter any further issues, please contact me back. I will be glad to assist you.

    Sincerely yours,
    Boryana
    the Telerik team


    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.

  10. Rick Petersen
    Rick Petersen avatar
    13 posts
    Member since:
    Feb 2009

    Posted 07 Aug 2009 Link to this post

    Boryana,

    Thank you for the response verifying that this is indeed the default behavior and that there is no provided option within the component for a work-around.  I would recommend, but I'm sure having made modification like this to components in the past you guys would do this anyway, that you leave the current functionality as the default so as not to break compatibility and provide a property on the Telerik.WinControls.Data.FilterExpression (if that's where the stripping is occurring) to tell it not to strip spaces.  I can see times where it may be desirable, but most certainly for existing implementations.


    Telerik.WinControls.Data.FilterExpression filter = new Telerik.WinControls.Data.FilterExpression(); 
    filter.Predicates.Add(Telerik.WinControls.Data.FilterExpression.BinaryOperation.AND, GridKnownFunction.EqualTo, GridFilterCellElement.ParameterName); 
    filter.Parameters.Add(GridFilterCellElement.ParameterName, radGridView1.CurrentRow.Cells["ColumnName"].Value.ToString()); 
    filter.StripLeadingSpaces = false
    radGridView2.Columns["ColumnToFilter"].Filter = filter


    That would be sweet.

    Thank you for listening and for the great tools; for every question or problem I post here, I have 100 success stories of your tools saving time and/or enhancing the look and feel of my applications.

    -Rick

  11. Rick Petersen
    Rick Petersen avatar
    13 posts
    Member since:
    Feb 2009

    Posted 07 Aug 2009 Link to this post

    Made a blog post on my personal blog about filtering with the radGridView, and including a link here and the work-around:

    Rick Petersen's blog post on radGridView filtering with strings

  12. Boryana
    Admin
    Boryana avatar
    329 posts
    Member since:
    Sep 2012

    Posted 07 Aug 2009 Link to this post

    Hi Rick Petersen,

    Our team highly appreciates your feedback and we are happy to see that in most cases RadGridView covers your expectations. Your blog post states both the advantages of RadGridView and its week sides which marks the direction for future improvement on our side. Once again thank you very much for evaluating our controls.

    I have updated your Telerik points for your blog post. If there is a way we can assist you, please let us know.

    Best wishes,
    Boryana
    the Telerik team


    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.

  13. Shailesh
    Shailesh avatar
    5 posts
    Member since:
    Jul 2012

    Posted 18 Aug 2012 Link to this post

    Hello Telerik Team,

                          I am using RadGrid control on my C# windows form. I want to add filter for column so that my grid should look like as following image. Please guide me how to achive this .



    Thanks,
    Shailesh

  14. Boryana
    Admin
    Boryana avatar
    329 posts
    Member since:
    Sep 2012

    Posted 22 Aug 2012 Link to this post

    Hi Shailesh,

    Thank you for writing.

    The screenshot you provided suggests that would like to enable the basic filtering functionality of RadGridView. You will be able to find more information on the topic here: http://www.telerik.com/help/winforms/gridview-filtering-basic-filtering.html.

    In case I did not understand your question correctly, I kindly ask to you open a separate thread and provide further details there.

    Regards,
    Boryana
    the Telerik team

    RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>

Back to Top