This is a migrated thread and some comments may be shown as answers.
Boolean Filter
2 Answers 9 Views
This is a migrated thread and some comments may be shown as answers.
Eric
Top achievements
Rank 1
Eric asked on 17 Jun 2013, 02:01 PM
Hello,
I have a RadDataFilter with a number of filters defined including some Boolean filters. They are defined like this:

ItemPropertyDefinition hasEventActivityDefinition = new ItemPropertyDefinition("EV_HasEventActivity", typeof(bool), "Has Event Activity");
                    this.radDataFilter.ItemPropertyDefinitions.Add(hasEventActivityDefinition);

When the user selects this filter the checkbox is initially unchecked as seen in screenshot #1.
In this case the user intends to use the filter "Has Event Activity = false", so they make no changes and save the filter (I am saving the filter contents to a database). However, in this case when I look at the filter descriptors the value for this filter is <Unset> as seen below:

? control.radDataFilter.FilterDescriptors[0]
{EV_ConstituentHasEventActivity IsEqualTo <Unset>}
    [Telerik.Windows.Data.FilterDescriptor]: {EV_ConstituentHasEventActivity IsEqualTo <Unset>}


A work-around I have discovered is if I check off the box, and then uncheck it, the value will successfully be set to "False".

Is there a way I can ensure that if the user adds the filter and does not touch the checkbox at all, that the value of the filter descriptor is set to "False" rather than staying as <Unset>?

Thank you.

2 Answers, 1 is accepted

Sort by
0
Accepted
Rossen Hristov
Telerik team
answered on 18 Jun 2013, 08:57 AM
Hi,

You can do the following by attaching to the EditorCreated event:

private void radDataFilter1_EditorCreated(object sender, EditorCreatedEventArgs e)
{
    var checkBox = e.Editor as CheckBox;
    if (checkBox != null)
    {
        checkBox.Loaded += checkBox_Loaded;
    }
}
 
void checkBox_Loaded(object sender, RoutedEventArgs e)
{
    ((CheckBox)sender).Loaded -= this.checkBox_Loaded;
    ((CheckBox)sender).IsChecked = null;
    ((CheckBox)sender).IsChecked = false;
}

I am setting it to null first (this does not affect anything, i.e. no filtering will occur), because when I then set it to false on the next line a PropertyChanged event will be raised and the respective filtering viewmodel will update its Value property from UnsetValue to false. 

This code should make sure that every boolean filter that you create will be born with a value of false instead of Unset and the data engine will perform the respective filtering operation.

I hope this helps. 

Regards,
Rossen Hristov
Telerik

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Eric
Top achievements
Rank 1
answered on 19 Jun 2013, 01:20 PM
That solution worked perfectly and solved my issue.

Thank you.
Asked by
Eric
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Eric
Top achievements
Rank 1
Share this question
or