Filtering boolean columns

3 posts, 1 answers
  1. Marcus
    Marcus avatar
    14 posts
    Member since:
    Sep 2010

    Posted 06 Jun 2013 Link to this post

    I have set a default filter on a boolean column in my RadGridView, so that it should only display rows where that column's values are true.  This works correctly, in that all the True rows are hidden.

    However, because my backing collection only currently contains rows with a False value, the filter popup only shows the False checkbox option for selection, and doesn't show the True option that is actually checked.  See attached image.

    This of course means that my default filter doesn't make any sense to the user until some rows with a True value arrive, which in this case could be hours.  They also can't clear the filter and then re-enable it for True values, as the True checkbox isn't there.

    Given this is a boolean column, and there should always be True and False options, surely both options should always display as checkable options?  I understand this behaviour for columns that have infinite possible values, but not so much for finite values such as those in bool or enum columns.

    Any suggestions for how I could tweak this for the desired behaviour?  I note that enum columns display all possible values in the Filter dropdown selectors (but not as checkable boxes) - even enabling this for bool columns would be useful.

    Thanks in advance.

  2. Answer
    Rossen Hristov
    Rossen Hristov avatar
    2478 posts

    Posted 07 Jun 2013 Link to this post


    By default the distinct values are extracted from the data source, which is normal.

    Please, attach to the DistinctValuesLoading event of the grid and tell it to use those two values: true and false. Something like this:

    private void OnRadGridViewDistinctValuesLoading(object sender, Telerik.Windows.Controls.GridView.GridViewDistinctValuesLoadingEventArgs e)
        e.ItemsSource = new List<bool>(){true, false};

    The other sections under the filtering HowTo's contain other interesting features.

    I hope this helps.

    Rossen Hristov

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. Marcus
    Marcus avatar
    14 posts
    Member since:
    Sep 2010

    Posted 07 Jun 2013 Link to this post

    Perfect, thanks!
Back to Top