TreeListView focus

Grids for WPF Forum

The latest build of this product (v22.1.4) was released 25 days ago, which was before this thread was created.
Posted 22 days ago by Olivier
Version: 22.1.4

Hi Friends,

In a TreeListView with several items :

1. User selects an item by click => Tree get focused, item is selected

2. User clicks elsewhere in the application => I sets programmatically Tree.SelectedItem = null => Tree loses focus, item is unselected

3. User clic in the empty space of the Tree => focus is given back to the previously focused item ...

Question : how can I prevent this behaviour ?

Thanks ;o)

[Modified 22 days ago]

Comments (8)

Posted 21 days ago by Actipro Software Support - Cleveland, OH, USA


If you mean to the right side of a TreeListViewItem past the columns, unfortunately the TreeListViewItem container stretches the entire width of the control similar to items in a normal WPF ListView.  So the item you click to the right of will end up being selected.

If you mean clicking under the last item in the whitespace of the TreeListView, I don't believe anything happens by default when clicking there.

Perhaps you can tell us how to reproduce this in one of our samples so that we can better understand the scenario.

Actipro Software Support

Posted 21 days ago by Olivier

Some clarifications :

Clicking "under the last item" does nothing, I agree with that.

Steps to reproduce are quite simple :

1. Select an item in the Tree (by clicking or programatically).

2. Give the focus to anything but the Tree.

3. Programatically (because this is the only way), set Tree.SelectedItem = null

4. Give back the focus to the Tree (by clicking under the last item, or by clicking a direct UI visual parent of the Tree).

=> Previously selected item is selected back, despite the current Tree.SelecteItem = null just before the Tree getting back the focus.

PS : I've not installed samples, and cannot do so, because installing it forces me to remove my previous install, and I'm not ready to upgrade yet.

Posted 20 days ago by Actipro Software Support - Cleveland, OH, USA

Hi Olivier,

We see that when tabbing back into the control, there is logic in TreeListBoxItem.OnGotFocus that selects the item.  There isn't currently an option to turn that off.  We are going to add a TreeListBox.CanSelectItemOnFocus property in v23.1 that will default to false (minor breaking change) that will make the behavior like other native ListBox/ListView controls.

Actipro Software Support

Posted 20 days ago by Olivier

Great news thanks !

But there is something weird :

Just before you give back the focus to the Tree, there is no item selected or focused, so the focus should be given back to the Tree himself, not to a TreeListBoxItem ?

[Modified 20 days ago]

Posted 19 days ago by Actipro Software Support - Cleveland, OH, USA


Are you saying you're seeing this behavior now or you'd like to see that behavior?  We try to mimic how ListBox works, and the native WPF ListBox doesn't have a tab stop itself.  If there are no items in it, focus skips over the whole control, which should be how ours works as well.

Actipro Software Support

Posted 19 days ago by Olivier

This is the behavior I'm seeing.

When application starts and nothing is selected in the Tree, if you give the focus to the tree by clicking on it (but not on an item !!), the focus is given to the tree (apparently, maybe to the Scrollviewer inside it ...), but SelectedItem remains null.

From the moment an item is selected in the tree, even after "nullifying" the SelectedItem, each time the tree get the focus back, the last selected item is focus & selected.

I would like this very last behavior to be disabled.

Posted 18 days ago by Actipro Software Support - Cleveland, OH, USA


Yes the last behavior you described is what we are changing for v23.1 to work like ListBox and how you want by default. We are adding a TreeListBox.CanSelectItemOnFocus property that will default to false (your desired behavior) and can be set to true for anyone who wants current behavior.  Since it's an internal code changed that was required, I don't think there's a way for you to prevent the current behavior until you get the next version.

Actipro Software Support

Posted 18 days ago by Olivier

Thanks a lot for your efforts and quick fix !

Add Comment

Please log in to a validated account to post comments.