diff --git a/news/665-bugfix.md b/news/665-bugfix.md new file mode 100644 index 000000000..89427e599 --- /dev/null +++ b/news/665-bugfix.md @@ -0,0 +1 @@ +Fixed tree view loosing selected index when updating/ignoring a failure (in tree view) \ No newline at end of file diff --git a/src/applications/Applications.IsIdentifiableReviewer/Views/RulesView.cs b/src/applications/Applications.IsIdentifiableReviewer/Views/RulesView.cs index fa6b55f36..fd0461477 100644 --- a/src/applications/Applications.IsIdentifiableReviewer/Views/RulesView.cs +++ b/src/applications/Applications.IsIdentifiableReviewer/Views/RulesView.cs @@ -218,8 +218,31 @@ private void Ignore(OutstandingFailureNode ofn, bool isBulkIgnore) /// private void Remove(ITreeNode obj) { - _treeView.GetParent(obj)?.Children?.Remove(obj); - _treeView.RefreshObject(obj,true); + var siblings = _treeView.GetParent(obj)?.Children; + + if(siblings == null) + { + return; + } + + var idxToRemove = siblings.IndexOf(obj); + + if(idxToRemove == -1) + { + return; + } + + + // remove us + siblings.Remove(obj); + + // but preserve the selected index + if (idxToRemove < siblings.Count) + { + _treeView.SelectedObject = siblings[idxToRemove]; + } + + _treeView.RefreshObject(obj, true); }