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

Programmatically set filters

2 Answers 205 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Sieg
Top achievements
Rank 1
Sieg asked on 01 Apr 2010, 02:33 PM
I tried to set filters for the GridView but it crashes. The error is the following one :

Expression of type 'System.Object' cannot be used for parameter of type 'System.String' of method 'Boolean Contains(System.String)'




I'm not sure why, is the code wrong or something. See below, I tried adding a filter descriptor, both ways but doesn't work.

FilterDescriptor ofilter = new FilterDescriptor(); 
ofilter.Member = radGridView1.Columns["Type"].UniqueName; 
ofilter.Operator = FilterOperator.IsContainedIn; 
ofilter.Value = sMask.ToString(); 
radGridView1.FilterDescriptors.Add(ofilter); 
radGridView1.FilterDescriptors.Add(new FilterDescriptor("Type", FilterOperator.IsContainedIn, sMask)); 

I tried the same way as setting a sort in the rows and this one works well.

SortDescriptor descriptor = new SortDescriptor(); 
descriptor.Member = "Type"
descriptor.SortDirection = ListSortDirection.Ascending; 
radGridView1.SortDescriptors.Add(descriptor); 

Work around or sample code would be appreciated.
Thanks,
Siegfrid

2 Answers, 1 is accepted

Sort by
0
Accepted
Rossen Hristov
Telerik team
answered on 05 Apr 2010, 09:45 AM
Hello Siegfrid Ducharme,

What is the type of the column that you are trying to filter with "Contains"? It must be a string otherwise Contains cannot possibly work. Is it a string? Can you try specifying the column type to be a string and see how it will go.

In case you are still experiencing problems, could you please send us your sample project. We need something to debug in order to see what is going on. You can open a separate support ticket and attach the sample project. Thanks in advance.

Greetings,
Ross
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Sieg
Top achievements
Rank 1
answered on 05 Apr 2010, 04:06 PM
Yes, the column I want to filter contains a string. It's linked to a dataTable or a dataSet. The values are displayed right if I skip the code for the filter. Tomorow, I will send a sample of my code.

Thanks,
Siegfrid
Tags
GridView
Asked by
Sieg
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Sieg
Top achievements
Rank 1
Share this question
or