Boolean Filter

3 posts, 1 answers
  1. Eric
    Eric avatar
    7 posts
    Member since:
    Nov 2011

    Posted 17 Jun 2013 Link to this post

    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. Answer
    Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 18 Jun 2013 Link to this post

    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.

  3. DevCraft banner
  4. Eric
    Eric avatar
    7 posts
    Member since:
    Nov 2011

    Posted 19 Jun 2013 Link to this post

    That solution worked perfectly and solved my issue.

    Thank you.
Back to Top