TreeNodes

B

bobbyballgame

Just started with the Windows Fomrm programming and I am running into
somethings that I feel should be done in a better way than I am now doing
them.

TreeNodes: Is there an easy way to get the level of the node?
I set up a hierarchy which is strict - something on the first level will be
a general root, levels below that are containers, and levels below that are
specific items, and depending on the level some very different behavior
ensues.

Also, if I want to find a specific node from the key - is it possible to do
that without iterating?
(e.g. TreeNode node = MyTreeNodeCollection.GetNodes(MyKey)[0] - or something
like that )

Any advice on dealing with TreeNodes would be helpful.
Thanks,
BB
 
L

Lloyd Sheen

Quickest way I know is to get the FullPath of the selected node. You can
then use split to find the number of items returned. That will indicate the
level.

Lloyd Sheen
 
B

bobbyballgame

Lloyd,

Thanks. I was thinking of that -- would you use the [PathSeparator] property
to use the value to split ( and is there a way to guarantee that I do not
get into some kind of escaping disaster?

For example, Using brackets to separate values for a visual clues, If my
hierarchy of items was something like:
[My\Root]\[My\nContainer]\[My\Item]

is the class smart enough to automatically escape? ( If I split on
[PathSeparator] would that return 3?, or would I have to manually take care
of that?
Thanks,
I guess I will just test it out. Any easy way to navigate to a certain
node - let me give you an example of what happens
I receive a data bundle that lists [Items] as well as an ID for a container.
Using that ID, I want to add the itmes to the TreeNode specified by the ID.
I was wondering if I could do TreeNode.GetNodeByName(ID), or if I should go
ahead and keep track of a table that relates nodes to Ids.

Thanks again,
BB


Lloyd Sheen said:
Quickest way I know is to get the FullPath of the selected node. You can
then use split to find the number of items returned. That will indicate the
level.

Lloyd Sheen

bobbyballgame said:
Just started with the Windows Fomrm programming and I am running into
somethings that I feel should be done in a better way than I am now doing
them.

TreeNodes: Is there an easy way to get the level of the node?
I set up a hierarchy which is strict - something on the first level will be
a general root, levels below that are containers, and levels below that are
specific items, and depending on the level some very different behavior
ensues.

Also, if I want to find a specific node from the key - is it possible to do
that without iterating?
(e.g. TreeNode node = MyTreeNodeCollection.GetNodes(MyKey)[0] - or something
like that )

Any advice on dealing with TreeNodes would be helpful.
Thanks,
BB
 
L

Lloyd Sheen

If you are worried about the seperator showing in your nodes use the
backspace characater as the PathSeparator. I cannot see a way to have
backspace as a character in a node.

Lloyd Sheen

bobbyballgame said:
Lloyd,

Thanks. I was thinking of that -- would you use the [PathSeparator] property
to use the value to split ( and is there a way to guarantee that I do not
get into some kind of escaping disaster?

For example, Using brackets to separate values for a visual clues, If my
hierarchy of items was something like:
[My\Root]\[My\nContainer]\[My\Item]

is the class smart enough to automatically escape? ( If I split on
[PathSeparator] would that return 3?, or would I have to manually take care
of that?
Thanks,
I guess I will just test it out. Any easy way to navigate to a certain
node - let me give you an example of what happens
I receive a data bundle that lists [Items] as well as an ID for a container.
Using that ID, I want to add the itmes to the TreeNode specified by the ID.
I was wondering if I could do TreeNode.GetNodeByName(ID), or if I should go
ahead and keep track of a table that relates nodes to Ids.

Thanks again,
BB


Quickest way I know is to get the FullPath of the selected node. You can
then use split to find the number of items returned. That will indicate the
level.

Lloyd Sheen

bobbyballgame said:
Just started with the Windows Fomrm programming and I am running into
somethings that I feel should be done in a better way than I am now doing
them.

TreeNodes: Is there an easy way to get the level of the node?
I set up a hierarchy which is strict - something on the first level
will
be
a general root, levels below that are containers, and levels below
that
are
specific items, and depending on the level some very different behavior
ensues.

Also, if I want to find a specific node from the key - is it possible
to
do
that without iterating?
(e.g. TreeNode node = MyTreeNodeCollection.GetNodes(MyKey)[0] - or something
like that )

Any advice on dealing with TreeNodes would be helpful.
Thanks,
BB
 

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