From 1dfef669122aab402b5360bfdcd4124535a04e39 Mon Sep 17 00:00:00 2001 From: Ed Harvey Date: Sun, 18 Dec 2011 18:09:37 +1100 Subject: [PATCH] Only modify focus if all previously selected nodes have been removed. --- SharpTreeView/SharpTreeView.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/SharpTreeView/SharpTreeView.cs b/SharpTreeView/SharpTreeView.cs index 7d44e0744b..74467feba4 100644 --- a/SharpTreeView/SharpTreeView.cs +++ b/SharpTreeView/SharpTreeView.cs @@ -151,11 +151,13 @@ void flattener_CollectionChanged(object sender, NotifyCollectionChangedEventArgs if (selectedOldItems != null) { var list = SelectedItems.Cast().Except(selectedOldItems).ToList(); SetSelectedItems(list); + if (SelectedItem == null) { + // if we removed all selected nodes, then move the focus to the node + // preceding the first of the old selected nodes + SelectedIndex = Math.Max(0, e.OldStartingIndex - 1); + FocusNode((SharpTreeNode)SelectedItem); + } } - // reset the focus to the previous node - SelectedIndex = Math.Max(0, e.OldStartingIndex - 1); - if (SelectedItem != null) - FocusNode((SharpTreeNode)SelectedItem); } }