This is a migrated thread and some comments may be shown as answers.

Pre-Filter not working

2 Answers 56 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Håkan
Top achievements
Rank 1
Håkan asked on 22 Nov 2013, 08:49 AM
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 Answers, 1 is accepted

Sort by
0
Accepted
Yoan
Telerik team
answered on 22 Nov 2013, 05:05 PM
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 >>
0
Håkan
Top achievements
Rank 1
answered on 26 Nov 2013, 09:20 AM
Thanks Yoan!

That worked much better for me.

Regards,
Håkan
Tags
GridView
Asked by
Håkan
Top achievements
Rank 1
Answers by
Yoan
Telerik team
Håkan
Top achievements
Rank 1
Share this question
or