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

Filtering boolean columns

2 Answers 271 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Marcus
Top achievements
Rank 1
Marcus asked on 06 Jun 2013, 02:22 PM
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.

Marcus.

2 Answers, 1 is accepted

Sort by
0
Accepted
Rossen Hristov
Telerik team
answered on 07 Jun 2013, 08:50 AM
Hello,

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.

Regards,
Rossen Hristov
Telerik

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Marcus
Top achievements
Rank 1
answered on 07 Jun 2013, 09:43 AM
Perfect, thanks!
Tags
GridView
Asked by
Marcus
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Marcus
Top achievements
Rank 1
Share this question
or