Avatar of Mike Littlewood
Mike LittlewoodFlag for United Kingdom of Great Britain and Northern Ireland

asked on 

Indicate children in a virtual string tree without actually loading them

Hi all,

I am using the Virtual Tree View from http://www.soft-gems.net/

Previously when using the standard TTreeView component, you used to be able to indicate whether or not a node has children without actually loading the data.  
node.hasChildren := true; // or some expression to indicate.

What I would like to know is if there is a way to do this with the virtual tree view component as well.
only thing I can see that puts the + sign at a node is the childCount property
Delphi

Avatar of undefined
Last Comment
Mike Littlewood
ASKER CERTIFIED SOLUTION
Avatar of SteveBay
SteveBay
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of MerijnB
MerijnB
Flag of Netherlands image

>   Node.States := Node.States + [vsHasChildren];

That's the wrong way to do it!
That way only the node knows, the tree itself doesn't so the tree isn't updated.
use:

VirtualStringTree.HasChildren[Node] := true;
Avatar of Mike Littlewood

ASKER

Excellent, thanks Steve.
Avatar of Mike Littlewood

ASKER

Interestingly the treeview doesnt seem to be very responsive to change in states visually.

Either if I use
VirtualStringTree.HasChildren[Node] := true;
or
Node.States := Node.States + [vsHasChildren];

The + sign doesn't seem to disappear unless you actually try and click it.
Is there a repaint issue?
Avatar of SteveBay
SteveBay
Flag of United States of America image

I am doing the Node.States := Node.States + [vsHasChildren]; in the InitNode event and it has always work for me. At the time I do this there are, in fact, no childern for that node and I determine if there are children in OnExpanded event.
Avatar of Mike Littlewood

ASKER

So you are setting all your nodes to be marked as having children and then when you click to expand the node, it removes the + if it cannot find any?
Avatar of SteveBay
SteveBay
Flag of United States of America image

That is exaclty what I am doing. Becuase my data are dynamic - in order for that work properly I also have to delete the children when the node is colapsed.
Avatar of MerijnB
MerijnB
Flag of Netherlands image

> I am doing the Node.States := Node.States + [vsHasChildren]; _in the InitNode event_

ah, you didn't mention that, afaik this will only work in the initnode event, not somewhere else
Avatar of Mike Littlewood

ASKER

I'm pretty much doing something similar to you Steve but I'm not deleting the children when collapsing.

procedure TfmTreeViewTest.VirtualStringTree1Expanding( sender: TBaseVirtualTree;
   Node: PVirtualNode; var Allowed: Boolean);

var
   curObject: TObject;
begin
   inherited;
   // checks if children have already been populated and if so allows the node
   // to expand without trying to add the children again
   if sender.childCount[ node] > 0 then
   begin
      allowed := true;
      exit;
   end;

   if assigned( node) then
   begin
      curObject := TObject( sender.getNodeData( node)^);
      allowed := buildChildNodes( node, curObject);
   end;
end;

Anyway, thanks for the information both of you.
Avatar of MerijnB
MerijnB
Flag of Netherlands image

see also this: http://support.soft-gems.net/forums/viewtopic.php?t=781&highlight=isvisible

it's on node visibility, but same applies to HasChildren.

note the bold part written by the author of TVirtualTree :)
Avatar of SteveBay
SteveBay
Flag of United States of America image

Interesting. I have changed my code to vTree.HasChildren[Node] := True; and this work just as well.
I cannot think of a good reason to contradict MerijnB nor would I wish to question the authority of Mike Lischke (he's written a true awesome component). Thanks for setting me straight MerijnB.
This reminds me why I participate here  I frequently learn more when answer Qs than when asking them.
Sorry about the points ;-)
Avatar of MerijnB
MerijnB
Flag of Netherlands image

I don't care about the points, sharing knowledge (me to others as well as others to me) is much more fun.
The thing is that if you change something in a node record, the tree doesn't know it, so it won't update until it 'accidentally' comes across that changed value for that node. It does work in OnInitNode because the tree will check the node right after that.
Avatar of Mike Littlewood

ASKER

Yeah sorry about the points, I would have shared them between the two of you if I wasn't so quick to accept :o)
Delphi
Delphi

Delphi is the most powerful Object Pascal IDE and component library for cross-platform Native App Development with flexible Cloud services and broad IoT connectivity. It provides powerful VCL controls for Windows 10 and enables FMX development for Windows, Mac and Mobile. Delphi is your choice for ultrafast Enterprise Strong Development™. Look for increased memory for large projects, extended multi-monitor support, improved Object Inspector and much more. Delphi is 5x faster for development and deployment across multiple desktop, mobile, cloud and database platforms including 32-bit and 64-bit Windows 10.

60K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo