Hello,
I'm using xamDataGrid to display some info. Each row has a boolean field named IsActive. My task to add a checkbox under the grid 'Hide inactive items' to allow user manage his information. If checkbox is checked I need to apply filter and if unchecked I need to reset it.
I've tried the following code in checkbox checkedchanged event handler but it doesn't work -
private void CheckBox_Checked(object sender, RoutedEventArgs e)
{
var isChecked = ((CheckBox)sender).IsChecked == true;
if (isChecked)
var filter = new RecordFilter();
filter.FieldName = "IS_ACTIVE";
filter.Conditions.Add(new ComparisonCondition(ComparisonOperator.Equals, true));
_grid.FieldLayouts[0].RecordFilters.Add(filter);
}
else
_grid.FieldLayouts[0].RecordFilters.Clear();
Could you please advise the best solution for my case?
Hi Francis,
Sam's sample works as expected. I will use it as example to fix my app.
Thank you
Hi Mikhail,
Have you had a chance to test Sam's sample? If you have furhter questions, please let us know.
Thanks,
Mikhail,
I am attaching a sample that demonstrates it. Since I don't know how it's done in your application, I would like to ask you to test the attached sample and see it it's any different than what you are trying to do. If it's not, then please attach your sample and I can review it.
Thank you,Sam
Hi Sam,
Thanks for your hint regarding 'Unchecked' event.
The problem with my code that filter doesn't reset on Unchecked event.
Here is an example of my observations -
1) State - No filters,
Visible rows: Row1, Row2, Row3, Row4
2) State - Filter applied (Show only odd rows)
Visible rows: Row1, Row3 <-- This works perfectly.
3) State - I'm trying to reset filters, call _grid.FieldLayouts[0].RecordFilters.Clear();
Expected result: Row1, Row2, Row3, Row4
but Actual result is: Row1, Row3
So nothing is changed.
That's why I decided that either I did smth wrong or filter reset functionality doesn't work as expected.
I would really appreciate if you have an example of filters reset in action.
Regards,
Mikhail
Your code works for filtering it out, but there is an 'Unchecked' event that you can handle using the same event as the 'Checked' for your 'else' condition.
Let me know if you have any question.