Treeview Question

R

rhaazy

Using VS2003 C#

I have a treeview control that navigates through a database in non
heiarchal fashion. I start with the root node, which is just going to
be the name of the database, so it will always just be that one root
node. After that is expanded I will get a list of Computer Names from
a particular table. WHen I expand one of those nodes I get a list of
Categories pertaining to scan results. If I click on a category I get
a list of Attribute Names. Finally when I click on an Attribute Name I
get its corresponding value. All of these events are very unique. I
currently have a form with a button for each of them, so everytime I
click on something I have to click the right button to expand or get a
value. I would like to be able to use just the double click method and
be able to expand the nodes based on how far down the tree I am. I
need something like this
if (Treeview.Nodes[x])
some crap
if (Treeview.Nodes[x].Nodes[x])
some crap

where Nodes[x] would be index of what level of the tree is currently
being worked with.

Any help would be appreciated thanks.
 
R

rhaazy

Wow that sounds like the perfect propery however I can't find it.
I am using Visual Studio 2003 and coding in C#, the name of my treeview
is trv

Please explain to me in greater detail how to use this "depth"
property.
Check out the TreeNode.Depth property.

Tony

rhaazy said:
Using VS2003 C#

I have a treeview control that navigates through a database in non
heiarchal fashion. I start with the root node, which is just going to
be the name of the database, so it will always just be that one root
node. After that is expanded I will get a list of Computer Names from
a particular table. WHen I expand one of those nodes I get a list of
Categories pertaining to scan results. If I click on a category I get
a list of Attribute Names. Finally when I click on an Attribute Name I
get its corresponding value. All of these events are very unique. I
currently have a form with a button for each of them, so everytime I
click on something I have to click the right button to expand or get a
value. I would like to be able to use just the double click method and
be able to expand the nodes based on how far down the tree I am. I
need something like this
if (Treeview.Nodes[x])
some crap
if (Treeview.Nodes[x].Nodes[x])
some crap

where Nodes[x] would be index of what level of the tree is currently
being worked with.

Any help would be appreciated thanks.
 
R

rhaazy

Here is what I was looking for incase you are wondering.... I think
you were confusing my form treeview with a web treeview...anyway for
anyone out there looking for the right answer.

int treelevel = 0;
TreeNode tnTemp = Treeview.SelectedNode;

while (tnTemp.Parent != null)
{
treelevel++;
tnTemp = (TreeNode)tnTemp.Parent;
}

MessageBox.Show(treelevel.ToString());

This will display a Msg Box with the current depth of the selected node.
 

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