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

Gridview filtering on combobox columns

4 Answers 255 Views
GridView
This is a migrated thread and some comments may be shown as answers.
MP
Top achievements
Rank 1
MP asked on 18 Feb 2010, 06:57 PM

Hi all,

I have a grid with a combobox column and I have come to realize that filtering a combobox grid column is a problem. The only way to clear the filter in these types of column is to enter a blank value in the 'Custom' option. If I use the 'NoFilter' option, it works temporarily until I renable the filter, in which case I have the same issue. Has anyone else faced the same problem?

I tried the following methods: -

  1. Add a blank entry at the top of the combobox before binding. I was hoping somehow I can capture when the user selects this blank value and clear the filter, but I haven't been able to do so (from within the filterchanged event).
  2. I tried to capture when users select the 'NoFilter' option and clear the existing filter expression but that doesn't seem to work either.

If anyone has come across this scenario, please post the solution (and code if available). Thanks!

Regards,
MP

4 Answers, 1 is accepted

Sort by
0
MP
Top achievements
Rank 1
answered on 19 Feb 2010, 06:35 AM

Discovered a couple of points about these issues which I am listing below for others reference.

  1. This issue doesn't occur for drop-downs with string values (ValueMember field is a text field). If you have a drop-down with ValueMember field mapped to a numeric value (like id values), you will see this issue.
  2. Workaround used: Added a blank entry at the top of the drop-down and handled the Filter_Changed event to clear the existing filter (see code below)

       

     

     

    if (e.GridViewTemplate.FilterExpressions.Count > 0 && e.NewStartingIndex >= 0)

     

    {

     

        FilterExpression filter = e.GridViewTemplate.FilterExpressions[e.NewStartingIndex] as FilterExpression;

     

     

        if (filter != null && filter.Parameters.Count > 0)

     

        {

     

            if (filter.Parameters[0].Value != null && Validation.IsInteger(filter.Parameters[0].Value.ToString()) &&

     

     

                Convert.ToInt32(filter.Parameters[0].Value) == -1)

     

            {

     

                this.radGridView1.FilterChanged -= new Telerik.WinControls.UI.GridViewCollectionChangedEventHandler(this.radGridView1_FilterChanged);

     

                e.GridViewTemplate.FilterExpressions[e.NewStartingIndex].Parameters.Clear();

     

                this.radGridView1.FilterChanged += new Telerik.WinControls.UI.GridViewCollectionChangedEventHandler(this.radGridView1_FilterChanged);

     

            }

        }

    }

     

    0
    Accepted
    Jack
    Telerik team
    answered on 19 Feb 2010, 08:51 AM
    Hello MP,

    I am glad to hear that you have found a solution for this issue and thank you for sharing it with the community. Currently we are working on a new version of RadGridView where we will refactor the data layer including the filtering functionality. We will take into consideration this case and will try to eliminate the need of this work around. Should you have any other questions, don't hesitate to contact us.
     
    Sincerely yours,
    Jack
    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
    MP
    Top achievements
    Rank 1
    answered on 19 Feb 2010, 03:56 PM
    Thanks Jack. One more improvement suggestion - Add a clean API to clear existing filter on a column. It took me a while to figure out the solution.

    Regards,
    MP
    0
    Accepted
    Jack
    Telerik team
    answered on 22 Feb 2010, 08:39 AM
    Hello MP,

    Currently you can remove the filtering from a column by setting its Filter property to null. Here is an example:

    this.radGridView1.Columns["Name"].Filter = null;

    Please, tell us if you have an idea how to improve this API. We will appreciate it.

    Sincerely yours,
    Jack
    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.
    Tags
    GridView
    Asked by
    MP
    Top achievements
    Rank 1
    Answers by
    MP
    Top achievements
    Rank 1
    Jack
    Telerik team
    Share this question
    or