Solved

count a treeview root items

Posted on 2004-09-05
6
277 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 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi application Soap connection 5 123
LAN or WAN ? 11 96
Convert a string into a TDateTime 5 64
CheckListBox usage 3 72
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…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

821 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