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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Treeview control - removing child nodes from a specific node

Status
Not open for further replies.

vdeveloper

Programmer
Aug 5, 2000
42
IN
Is there an easy way to remove all child nodes from a node which itself is a child node of another? I have looked at the sibling, last sibling etc properties and written loop codes to remove the nodes. but they dont seem to work properly.<br><br>Thanks in advance<br><br>
 
It would help if you post some of your loop code and let us have a look.&nbsp;&nbsp; <p> <br><a href=mailto:blindpete@mail.com>blindpete@mail.com</a><br><a href= > </a><br>
 
<br>the code Im using is the following<br><br><br>tvw = THISFORM.tvwMain &&&nbsp;&nbsp;tvwMain is the treeview control<br><br>&nbsp;&nbsp;&nbsp;If tvw.SelectedItem.Children &gt; 0 &&' There are children.<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&& Get first child's text, and set N to its index value.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strC = tvw.SelectedItem.Child.Text <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;N = tvw.SelectedItem.Child.Index<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&& While N is not the index of the child node's last sibling, get next sibling's text.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;do While N &lt;&gt; tvw.SelectedItem.Child.LastSibling.Index<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mkey = tvw.Nodes(N).Next.key<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;N = tvw.Nodes(N).Next.Index<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tvw.nodes.remove(mkey)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;enddo<br>&nbsp;&nbsp;&nbsp;Else &&' There are no children.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Messagebox(tvw.SelectedItem.Text + &quot; has no children&quot;,64,'Attention')<br>&nbsp;&nbsp;&nbsp;EndIf<br><br>somehow the first 1 or 2 nodes always remain<br><br>Thanks<br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top