Solved

count a treeview root items

Posted on 2004-09-05
6
273 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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 Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now