Solved

count a treeview root items

Posted on 2004-09-05
6
279 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 100 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

688 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