Filtering Question

6 posts, 1 answers
  1. DDM Consulting
    DDM Consulting avatar
    9 posts
    Member since:
    Feb 2010

    Posted 07 Oct 2010 Link to this post

    How can I keep the gridview from applying its filterdescriptor untill the user presses enter in the filtercell (or leaves the cell by tab or click ie: the cellEndEdit event has passed (with rowIndex == -1))?

    eg:
    i have a column and I enter the filter string "abc" by typing the 3 character. Normally the grid will first add the fitlerdescriptor A  then AB then ABC. Now  I would like the behaviour of my gridview to be abc + "LEAVES FILTERFIELD" and then apply only 1 filterdescriptor ABC..

    I have tried using a boolean "holdFiltering" which i set to true when the cellBeginEdit is fired on RowIndex == -1  and then i set it back to false at cellEndEdit, but unfortunately the cellEndEdit is fired AFTER the FilterChanging event (where i used the holdFiltering to set the e.Cancel = true & return from the method), this resulted in no more filtering whatsoever ;-)

    Can anyone point me to or show me a working code snippet?

    thank you in advance!
  2. Answer
    Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 07 Oct 2010 Link to this post

    Hello DDM Consulting,

    Please try the following:
    private FilterDescriptor lastFilterDescriptor;
     
    void radGridView1_FilterChanging(object sender, GridViewCollectionChangingEventArgs e)
    {
        if (radGridView1.IsInEditMode)
        {
            if (e.Action == NotifyCollectionChangedAction.Remove)
            {
                lastFilterDescriptor = null;
            }
            else
            {
                lastFilterDescriptor = e.NewItems[0] as FilterDescriptor;
            }
     
            e.Cancel = true;
        }
    }
     
    void radGridView1_CellEndEdit(object sender, GridViewCellEventArgs e)
    {
        var filteringRow = e.Row as GridViewFilteringRowInfo;
        if (filteringRow != null)
        {
            radGridView1.FilterDescriptors.Remove(e.Column.Name);
            if (lastFilterDescriptor != null)
            {
                radGridView1.FilterDescriptors.Add(lastFilterDescriptor);
            }
             
        }
    }

    I was thinking the following: hold the last descriptor as a local field and cancel the filter changing event, and on CellEndEdit just apply the last filter stored.

    Hope this helps, if you have any other questions or comments, please let me know,

    Best Regards,
    Emanuel Varga
  3. UI for WinForms is Visual Studio 2017 Ready
  4. DDM Consulting
    DDM Consulting avatar
    9 posts
    Member since:
    Feb 2010

    Posted 07 Oct 2010 Link to this post


    Emanuel,

    Thank you for your quick reply!
    it works very well!

    KR

  5. Umut
    Umut avatar
    6 posts
    Member since:
    Jul 2010

    Posted 21 Aug 2011 Link to this post

    Its work
  6. Jason Parrish
    Jason Parrish avatar
    87 posts
    Member since:
    Sep 2009

    Posted 12 Dec 2011 Link to this post

    It appears on the latest release (q3 2011) that NewItems is not updated properly.  NewValue updates correctly.  Is anybody else seeing the same problem?
  7. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 15 Dec 2011 Link to this post

    Hello Jason,

    Thank you for noticing this. 

    We are already aware of this case and it is logged into our PITS system. Here you can find a link to the item, where you can add your vote for it.

    Meanwhile, here is how you can achieve the same effect - to filter only when Enter key is press. First, create two variables lastFilterDescriptor of type FilterDescriptor and another one of type Boolean, let's call it isRealFiltering. Subscribe to the FilterChanging event handler, where you check weather the isRealFiltering is true and if so, you will change it back to false, alternatively, cancel the filtering. Now, in order to capture the Enter key press and set the isRealFiltering variable to true, you need to subscribe to the CellEditorInitialized event of RadGridView, get the editor and subscribe to the KeyDown event of the editor element.

    Attached you can find a sample project with the above scenario implemented. Please note that you need to instantiate and subscribe to the KeyDown event for all editors used in your grid. 

    I hope that you find this information helpful.
     
    Best wishes,
    Stefan
    the Telerik team

    Q3’11 of RadControls for WinForms is available for download (see what's new). Get it today.

Back to Top
UI for WinForms is Visual Studio 2017 Ready