Forum > Packages and Libraries

VirtualTreeView (VTV) select node after block delete



testing VTV I noticed that if I have toMultiselect enabed and delete the selected nodes, the tree looses its focused node. I set toAlwaysSelectNode and noticed, that if I do the first tree node is selected, which is even worse than select no node at all, since it scrolls the tree to the top. Usually, if I am working on nodes deep down a tree I want the focus to stay close, not to jump to the other end of the world.

Finally, after a while of studying man pages and options i vain, I wrote this code:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.SpeedButtonDelNodeClick(Sender: TObject); var  n,enm,fn,ln: PVirtualNode; begin  n := nil;  fn := nil;  ln := nil;  // get the first and last selected node  for enm in StudyStringTree.SelectedNodes do    begin    if not assigned(fn) then fn := enm;    ln := enm;    end;  // find the node to focus after the delete if assigned(fn) then   if assigned(fn^.PrevSibling) then     n := fn^.prevSibling   else     if assigned(ln^.NextSibling) then       n := ln^.NextSibling     else       n := fn^.Parent; StudyStringTree.DeleteSelectedNodes; // restore the focus if assigned(n) then   FocusNode(StudyStringTree,n);end;

which works like one would expect a tree to behave: if child nodes are deleted, and if there are siblings left, it will focus the previous or the next remaining sibling, if no sibling is left, it will focus the parent node.

Did I miss something, does the Treeview have any meaningful way to keep a node adjacent to the deleted nodes focused, or is my code an adequate solution for the problem?

Thnx, Armin.


[0] Message Index

Go to full version