treeView - deepest level

B

Bllich

can anyone post an algoritam for the deepest level
of a treeView ? it should be a recursive function I think..

I don't need treeView.Nodes[x].Level
because my users don't select the nodes...
I need to get a random node from the whole collection
so I want my
rndLevel = random.next(deepest level)
rndNode = random.next(number of nodes on that level)
to be able to get any node on any level in the collection.

please help..
 
B

Bllich

for my problem, with having only one node without Parent
seems this works ok..

ArrayList list = new ArrayList();

private void btn1_Click(object sender, EventArgs e)
{
depth(treeView1.Nodes[0]);
list.Sort();
MessageBox.Show("Deepest level: " + list[list.Count-1].ToString
());
}

private void depth(TreeNode node)
{
for (int i = 0; i < node.Nodes.Count; i++)
{
depth(node.Nodes);
list.Add(node.Nodes.Level);
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top