FocusItemByFullPath replaces selection

Grids for WPF Forum

The latest build of this product (v2019.1 build 0683) was released 1 month ago, which was before this thread was created.
Posted 21 days ago by Mike PB
Version: 19.1.0683
Platform: .NET Core 3.0
Environment: Windows 10 (64-bit)
Avatar

Hello,

I have a problem with FocusItemByFullPath in TreeListBox. Our application manages selection of multiple items within the TreeListBox, and I want to set focus to the primary item within that selection. However if I use FocusItemByFullPath, the item is focussed but my selection is lost.

What I would expect is that FocusItemByFullPath simply changes the focus, and does not affect selection at all. Perhaps changes to the selection could be optionally included for convenience.

What do you think?

Thanks, Mike

PS This is on .Net Framework

[Modified 21 days ago]

Comments (2)

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

Hi Mike,

We have a way where you can prevent selection change notifications until a "batch" is complete.  This would allow you to effectively restore the prior selection before any selection change events go.

I tested with this kind of code where I selected three items and then executed this code that focused the second one.  All three items were selected at the end of the batch.

using (var batch = treeListBox.CreateSelectionBatch()) {
	var oldSelectedItems = treeListBox.SelectedItems.ToArray();
					
	treeListBox.FocusItem(treeListBox.SelectedItems[1]);
					
	foreach (TreeNodeModel item in oldSelectedItems)
		item.IsSelected = true;
}


Actipro Software Support

Posted 20 days ago by Mike PB
Avatar

Thanks - that seems to work around the problem, and could be a useful pattern for us elsewhere.

Add Comment

Please log in to a validated account to post comments.