Changing default filtering option

2 posts, 1 answers
  1. Preety
    Preety avatar
    1 posts
    Member since:
    Aug 2017

    Posted 11 Aug Link to this post

    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;
                }
  2. Answer
    Stefan
    Admin
    Stefan avatar
    774 posts

    Posted 15 Aug Link to this post

    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.
Back to Top