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

Changing default filtering option

1 Answer 83 Views
DataFilter
This is a migrated thread and some comments may be shown as answers.
Preety
Top achievements
Rank 1
Preety asked on 11 Aug 2017, 12:48 PM
Hello,

If this post is not relevant please delete it. I am trying to get the data type of a table while filtering. My intention is  while user click on filter option it will check whether that column has string if it has string it will show filter option as "Contains" otherwise filter will display the default i.e Is Equals To. Below are my code.

This piece of code is working fine for all tables but in one table (for all column) while i am trying this code it gives a Null reference exceptions. Any suggestion how to debug and where should i look to fix this issue?

private void OnRadGridViewFilterOperatorsLoading(object sender, Telerik.Windows.Controls.GridView.FilterOperatorsLoadingEventArgs e)
        {
            var column = e.Column as GridViewDataColumn;
            if (column.DataType.Name == "String") //this returning me null reference exceptions(but few column of this table does have string value) for one table but for rest tables i am getting value
            {
                e.DefaultOperator1 = Telerik.Windows.Data.FilterOperator.Contains;
                e.DefaultOperator2 = Telerik.Windows.Data.FilterOperator.Contains;
            }

1 Answer, 1 is accepted

Sort by
0
Accepted
Stefan
Telerik team
answered on 15 Aug 2017, 12:56 PM
Hello Preety,

Thank you for the provided code.

Before proceeding to your inquiry, I would like to clarify that RadDataFilter is a completely separate component. From the provided information though, I assume that you refer to the RadGridView control instead. If this is the case, the only scenario in which I guess such NullReferenceException would be raised, is if there is a column of type different than GridViewDataColumn defined. In such case you can simply add a null check for the column variable in order to ensure that the column is actually a GridViewDataColumn.

I hope this helps. Additionally, you can take a look at the Column Types section from RadGridView's online help.

Regards,
Stefan X1
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
DataFilter
Asked by
Preety
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or