?
Solved

count a treeview root items

Posted on 2004-09-05
6
Medium Priority
?
285 Views
Last Modified: 2011-09-20
hey all,
anyone have a function that can count the root items in a treeview?
not the total item count, I dont want to count the children....
0
Comment
Question by:LMuadDIb
  • 4
  • 2
6 Comments
 
LVL 7

Expert Comment

by:DavidBirch2dotCom
ID: 11985043
You might be interested in a treeview which is a huge amount better than the delphi default one Virtual treeview from www.delphi-gems.com - it has a rootnodecount property and has many more options... its well worthwhile if you are going to be doing anything serious with a treeview

David

0
 
LVL 7

Accepted Solution

by:
DavidBirch2dotCom earned 400 total points
ID: 11985084
try this code

function TotalRootNodes(ATreeView: TTreeview): Integer;
var
 I,ANodes : Integer;
begin
  ANodes := 0;
  for I := 0 to ATreeView.Items.Count-1 do
     if ATreeView.Items[I].Parent = nil then
       inc(ANodes);
  Result := ANodes;
end;

A sample call would be

numItems:= TotalRootNodes(TreeView1);



its from this thread
http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_20693535.html

you might find something else useful from it

David
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 11987373
another possibility (just from head, not tested)

function countChilds(ATree : TTreeView;ANode : TTreeNode) : Integer;
var
  CNode : TTreeNode;
begin
  result := 0;
  if ANode = Nil then
    CNode := ATree.Items.GetFirstNode
  else
    cNode := ANode.GetFirstChild;
  if assigned(CNode) then
  begin
    while assigned(CNode) do
    begin
      result := result +1;
      cNode := cNode.GetNextSibling;
    end;
  end;
end;


meikl ;-)
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 7

Expert Comment

by:DavidBirch2dotCom
ID: 11987817
Thanks for the points :)

I beat the mighty kretzschmar  ;-p) he he ;)

David
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 11988360
:-))
i posted my suggestion already after you got the grade, david,
so you was never in danger :-))

btw. i'm not mighty, i'm just a simple coder

meikl ;-)
0
 
LVL 7

Expert Comment

by:DavidBirch2dotCom
ID: 11988379
lol ;P
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Loops Section Overview
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month15 days, 17 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question