Pre-Filter not working

3 posts, 1 answers
  1. Håkan
    Håkan avatar
    183 posts
    Member since:
    May 2011

    Posted 22 Nov 2013 Link to this post

    Hi!

    I have a GridView that I want to pre-filter with checkboxes.
    I have read a blog about this here
    http://blogs.telerik.com/xamlteam/posts/09-11-27/pre-filtering-radgridview-for-silverlight.aspx
    with the following code:

    ColumnFilterDescriptor countryColumnFilter = new ColumnFilterDescriptor((IDataFieldDescriptor)this.playersGrid.Columns[2]);
    countryColumnFilter.DistinctFilter.DistinctValues.Add("England");
    countryColumnFilter.DistinctFilter.DistinctValues.Add("Spain");
    this.playersGrid.FilterDescriptors.Add(countryColumnFilter);

    The problem is that I get an error saying that "Cannot create an instance of the abstract class or interface "Telerik.Windows.Controls.GridView.ColumnFilterDescriptor".

    Its pretty old code so I guess this has changed, but how do I do to make it work now?
    I use the last Silverlight 4 version.

    Regards,
    Håkan

  2. Answer
    Yoan
    Admin
    Yoan avatar
    1070 posts

    Posted 22 Nov 2013 Link to this post

    Hello Håkan,

    Actually, the mentioned forum post is quite old. Please check the following code snippet which demonstrates how to add ColumnFilterDescriptor:
    Telerik.Windows.Controls.GridViewColumn countryColumn = this.clubsGrid.Columns["Name"];
               Telerik.Windows.Controls.GridView.IColumnFilterDescriptor countryFilter = countryColumn.ColumnFilterDescriptor;
               countryFilter.SuspendNotifications();
     
               // This is the same as the end user selecting a distinct value through the UI.
               countryFilter.DistinctFilter.AddDistinctValue("Arsenal");
               countryFilter.DistinctFilter.AddDistinctValue("Spain");
               countryFilter.DistinctFilter.AddDistinctValue("Uzbekistan");
               countryFilter.DistinctFilter.AddDistinctValue("Netherlands");
               countryFilter.DistinctFilter.AddDistinctValue("Austria");
               countryFilter.DistinctFilter.AddDistinctValue("Finland");
               countryFilter.DistinctFilter.AddDistinctValue("Pakistan");       
     
               // Resume the notifications to force the data engine to update the filter.
               countryFilter.ResumeNotifications();

    I strongly recommend you to take a look at this help article as well.

    As a side note I must mention that the support for WPF 3.5 and Silverlight 4 has been discontinued as of Q3 2012. You can check this blog post for more information.



    Regards,
    Yoan
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. DevCraft banner
  4. Håkan
    Håkan avatar
    183 posts
    Member since:
    May 2011

    Posted 26 Nov 2013 Link to this post

    Thanks Yoan!

    That worked much better for me.

    Regards,
    Håkan
Back to Top