4

How to check if a node is visible (on screen) with VirtualTreeView component? Something like this:

if not Grid.NodeVisible (Node) then
   Grid.ScrollIntoView (Node, True);

The node should be centered if it was not visible, but remain where it is if it was visible.

Note that I am not talking about the node's visible flag, but about visility on the screen. The IsVisible property always returns True in my case.

jpfollenius
  • 16,456
  • 10
  • 90
  • 156
  • 1
    Now I don't think there's such property or function. Maybe `GetDisplayRect` and check the intersection with the tree view's clip rectangle. – TLama Mar 20 '12 at 08:39

2 Answers2

3

I think the closest thing there is is the GetDisplayRect() method:

Determines the client coordinates the given node covers, depending on scrolling, expand state etc. If the given node cannot be found (because one of its parents is collapsed or it is invisible) then an empty rectangle is returned.

Not sure what it returns in case the node is "visible but out of view" - you might have to write helper function which checks is the returned rect inside VT's client rectangle...

ain
  • 22,394
  • 3
  • 54
  • 74
  • +1, that's right. Still the question is why to check this, if the `ScrollIntoView` do this for you. – TLama Mar 20 '12 at 08:54
  • 1
    @TLama Because `ScrollIntoView` has not the behaviour I want: I want the node to be centered if it was not visible, but remain where it is if it was visible. This cannot be achieved by `ScrollIntoView` alone. – jpfollenius Mar 20 '12 at 09:09
  • True, it's return value even indicates was any scrolling done... however, the OP wrote "Something like" so perhaps he actually needs it in some other situation than checking before `ScrollIntoView` call. – ain Mar 20 '12 at 09:11
  • 1
    An implementation of the helper function you mention is available in https://stackoverflow.com/a/22298304/859646 – JRL Aug 28 '17 at 11:24
0

The IsVisible property only returns if the nodes has been hidden or not as you found. The only way to find if a node is on screen is to use the GetDisplayRect as ain suggested and then test it against the client rectangle of the tree view.

However, if I understand what you are trying to do correctly, the toCenterScrollIntoView option in the SelectionOption of the VirtualTreeView will give you the behavior you want without having to test if the node is in the visible area or not.

ie(C++):

TreeView->TreeOptions->SelectionOptions =
TreeView->TreeOptions->SelectionOptions << toCenterScrollIntoView ;
...
ScrollIntoView(Node);
dschaeffer
  • 618
  • 6
  • 15