Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
Solved

# count a treeview root items

Posted on 2004-09-05
Medium Priority
283 Views
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
[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
• 4
• 2

LVL 7

Expert Comment

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

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);

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

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

LVL 7

Expert Comment

ID: 11987817
Thanks for the points :)

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

David
0

LVL 27

Expert Comment

ID: 11988360
:-))
so you was never in danger :-))

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

meikl ;-)
0

LVL 7

Expert Comment

ID: 11988379
lol ;P
0

## Featured Post

Question has a verified solution.

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