winforms - C# - TreeView: inserting node at certain position -
how 1 insert new child particular node in treeview in c# winforms?
i've been clumsily stabbing @ treeviews hour , i'd use c#'s treeview this:
treeview.getchildbyname("bob").addchild(new node("bob's dog"));
here's tried last (which think @ level of hairiness c# should never have allowed me reach):
tree.nodes[item.name].nodes.add(new treenode("thing"));
needless say, doesn't work.
oh, , here's lazy question: can store objects in these nodes? or treenode support strings , whatnot? (in case should extend treenode.. /sigh)
please help, thanks!
actually code should work - in order add sub node have do:
mynode.nodes.add(new treenode("sub node"));
maybe problem in way refer existing nodes. guessing tree.nodes[item.name] returned null?
in order indexer find node, need specify key when add node. did specify node name key? example, following code works me:
treeview1.nodes.add("key", "root"); treeview1.nodes["key"].nodes.add(new treenode("sub node"));
if answer doesn't work, can add more details on happen? did exception or did nothing happen?
ps: in order store object in node, instead of using tag property, can derive own class treenode , store in it. if you're developing library, more useful because leaving tag property users use.
ran
Comments
Post a Comment