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

How to clean Excel like filters

2 Answers 139 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Mauricio
Top achievements
Rank 1
Mauricio asked on 02 Feb 2012, 07:26 PM
Hi,

I have enabled the Excel like filtering, but every time I change the DataSource on the radGridView, the filter for a column is not updated. I have tried to clean the filters using:

MasterTemplate.FilterDescriptors.Clear();

MasterTemplate.FilterExpressions.Clear();



But those collections are empty, since I'm not creating my own filters. Any help will be appreciated.
Thanks

2 Answers, 1 is accepted

Sort by
0
Mauricio
Top achievements
Rank 1
answered on 03 Feb 2012, 06:18 PM
I found a solution. To update the value that are shown on the "Excel" filters after changing the value of the DataSource, I have
to add a new row to the radGridView. (and then i remove it since I do not need it). Is this the only way to update the value of this filters? I feel like is not the right way to do it.

0
Stefan
Telerik team
answered on 07 Feb 2012, 02:06 PM
Hello Mauricio,

Thank you for writing.

If you have bound the grid and added some filtering for a column via the Excel-like filtering dialog, this automatically creates a FilterDescriptor according to the filtering conditions and this descriptor is added to the FilterDescriptors collection of the template. So when you change the data source of your grid, this filter is preserved if the columns schema of the new data source is the same as the previous one and the filters are cleared if the columns' schema is different. 

If you want to remove the filters upon changing the data source, call the Clear method of the FilterDescriptors collection of the desired template. Alternatively, if you want to keep them and if your data schema is the same, just change the data source and the filter will be kept. Attached you can find a sample project demonstrating both approaches. 

Let me know if you have any additional questions.
 
Greetings,
Stefan
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Tags
GridView
Asked by
Mauricio
Top achievements
Rank 1
Answers by
Mauricio
Top achievements
Rank 1
Stefan
Telerik team
Share this question
or