Filter clears selection

Grids for WPF Forum

Posted 7 years ago by Mike
Version: 18.1.0670
Platform: .NET 4.7
Environment: Windows 10 (64-bit)
Avatar

Hi,

I'm using a simple string filter on TreeListBox which is bound to a textbox. On filtering items the selected item property of the TreeListBox changes. Is there a way to keep the selected item until its changed by the user only? I've been looking for something like a "FilteringStarted" and "FilteringEnded" event so I can save/restore the selection.

Comments (10)

Answer - Posted 7 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Mike,

If you look at the IDataFilter in the TreeListBox's DataFilter property that you set, that has a FilterChanged event that fires.  That event fires whenever the filter enabled state changes, or one of the properties on the filter changes that could trigger a filter.  Perhaps you could look at that and see if your filter's properties have been updated in a way to know when filtering has started/stopped?


Actipro Software Support

Posted 7 years ago by Mike
Avatar

Thanks, it is not perfect but I was able to find a workaround using your suggestion.

Posted 7 years ago by Darcy Davidson
Avatar

Hi,

I noted this behavior as well and also found a non-perfect work around.  In my case it was clearing a multiselection.  Maybe something for a future release?

D'Arcy

Answer - Posted 7 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

This situation is tricky because there isn't a real true start/end of the filter.  The filtering mechanism is a basic interface.  Some filters are string-based, while others might run a code-based predicate over values.  In Mike's scenario, he's pretty much always got the filter on.  It's just that with an empty TextBox value, the filter is allowing everything through.  However he could just as easily have a delegate filter with complex code that we wouldn't know if it was filtering anything or not.  That's the main we can't really have a set of FilterStarted/FilterEnded events with the way you're thinking of them. 

We could have those events based on the IsFilterActive property value changing, but that wouldn't help in this scenario since the filter is always active.


Actipro Software Support

Posted 8 months ago by Chris
Avatar

I also encountered this problem. When I cleared the keywords in the text box, the selected items were lost.

Posted 8 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Chris,

I'm loading our TreeListBox Filtering QuickStart and I do these steps:

  1. Select the "Cuba" item.
  2. In the filter "Value" TextBox underneath that, type in "cuba".
  3. Click the "Is filter active" CheckBox in the options.
  4. Clear the "Value" TextBox.
  5. Uncheck the "Is filter active" CheckBox.

After all those steps, Cuba is still selected.  Can you tell us how to reproduce what you are seeing?


Actipro Software Support

Posted 8 months ago by Chris
Avatar

2. In the filter "Value" TextBox underneath that, type in "cubb".

There are no matches at this time, but when I clear the value, the original selection is gone. This behavior does not seem normal. I did not make any changes to the selection and it disappeared.

Posted 8 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Chris,

There are a lot of possible scenarios that could happen with filtering and selection and before considering any changes to logic, we should probably talk through them all.  In all cases, assume there is a pre-filter selection of "Cuba" in that sample.  What do you feel like the selection should be following each of these scenarios?

Scenario 1

  1. Type a "c" filter string that matches the selection, and activate the filter.
  2. Deactivate the filter.
Scenario 1b
  1. Same as Scenario 1 but after step 1, select "Canada".

Scenario 2

  1. Type a "c" filter string that matches the selection, and activate the filter.
  2. Change the filter to "cz".
  3. Deactivate the filter.
Scenario 2b
  1. Same as Scenario 2 but after step 1, select "Canada".
Scenario 2c
  1. Same as Scenario 2 but after step 2, select "Canada".

Scenario 3

  1. Type a "c" filter string that matches the selection, and activate the filter.
  2. Change the filter to "cz".
  3. Backspace over the "z" to restore the filter to "c".
  4. Deactivate the filter.

Scenario 4

  1. Type a "z" filter string that doesn't match the selection, and activate the filter.
  2. Deactivate the filter.

Scenario 5

  1. Type a "z" filter string that doesn't match the selection, and activate the filter.
  2. Change the filter to "c".
  3. Deactivate the filter.
Scenario 5b
  1. Same as Scenario 5 but after step 2, select "Canada".


Actipro Software Support

Posted 6 months ago by Dan Hutt
Avatar

I'm hitting a similar issue with this, but perhaps tangentially related. I did the steps in your post above here 


I agree that Cuba should stay selected there, and indeed it does. However, In some of your other scenarios above where Cuba is filtered OUT, the parent is being selected. Is there any way to turn off that behavior? I'd rather my selection not change at all if the user hasn't updated it while the filter is on. I'd even be happy if we could just not have the selection roll up in that way.

To add my own steps so my question is clearer:

  1. Open the Filtering QuickStart
  2. Select Cuba
  3. Turn on the filter (default is "g")
  4. Note North America is selected
  5. Turn off Filter
  6. Note that North America is still selected.

    In this case, I'd rather selection get cleared I guess, but it would be more ideal if the selection was cached as the filter was turning on and if it hasn't changed during the filter session, restore the selection.

Thanks for working on this complicated issue!

Answer - Posted 6 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Dan,

We are working on updating logic for the next release to try and persist the selection start prior to activating filtering, and then restore it when filtering ends, as long as the selection was not altered while filtering was active.


Actipro Software Support

The latest build of this product (v24.1.5) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.