Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Treeview slected node question... 1

Status
Not open for further replies.

NerdTop72

Programmer
Mar 14, 2005
117
US
Hi,

I have a treeview populated like so...

Node01
subNode01
subsubnode01
subsubnode02
subnode02
subnode03
Node02
Subnode01
Subnode02

I am trying to select a node and get the entire treelist location of that node. For instance, if you clicked subsubnode02 then how to i get the information node01-subnode01-subsubnode02?
I am trying to remove the selected node and nested child nodes(if there happens to be any) from a command button based on the selected node.

Thanks!




 
I'm not sure what exactly you want to do. Do you want to delete the selected node and any children of that node? Or do you want to delete the selected node and all of its parents up to the root?

If it is the first, you can do it like this:

TreeView1.SelectedNode.Remove()


For the second, try this:

Dim node As TreeNode

node = TreeView1.SelectedNode

Do Until (node.Parent Is Nothing)
node = node.Parent
Loop

node.Remove()



I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Thanks jebenson!

Do Until (node.Parent Is Nothing)
node = node.Parent
Loop

Worked good. I am using the tree view to display DB information so I needed to know what it represented in the tree view to remove it from the DB as well.

Thanks Again!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top