Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
| Search | Today's Posts | Mark Forums Read
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old June 23rd, 2006, 10:02 AM
Registered User
 
Join Date: Oct 2005
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default tree view delete..Urgent help plz

Hi,
i have a folder view which list all my folders in a tree view form. My requirement is, after selecting a folder if i send a delete command it has to delete all folders and its contents. Problem is only after deleting the files in the subfolders,i can delete the folder. i need to do an recursive search. Urgent.... plzzzzzzzz reply. I am using c# windows application.
e.g
1
 11
 12
   121
   122
 13

say my tree view looks like this... if i delete the folder 1. it should find out all the subfolders. Should delete 13 first and 122 and then 121 and 12 and 11.

plzzzzzzz do guide me... Thanks in advance...:(
  #2 (permalink)  
Old June 23rd, 2006, 06:34 PM
Authorized User
 
Join Date: May 2006
Location: Chico, CA, USA.
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Off the top of my head:

void DeleteNode (TreeView parent_tree, TreeNode selected_node)
{
    if (selected_node != null)
    {
        for (int x = 0; x < selected_node.Nodes.Count; x++)
            DeleteNode (selected_node.Nodes[x]);

        // logic for removing node from parent_tree.
    }
}


This is a recursive function that loops through and deletes all the child nodes of a particular node before deleting that node. Note that each time the function gets called, it first loops into the child nodes of the one passed in the parameter, until one is reached that has no children. THEN the logic for removing the node from the tree is executed.

The EXIT CONDITION for this recursive logic is to reach a node that has no children. This is reasonable, so long as we no that the tree view doesn't have an infinite child structure (which it shouldn't). Alternatively, a null value in the selected_node parameter will stop the function.

Be careful with recursive functions! Incorrectly used, they can create bad stuff!


Brandon


Similar Threads
Thread Thread Starter Forum Replies Last Post
Urgent - Send mail with plain view and html view ashish.dadhwal ASP.NET 2.0 Professional 0 November 27th, 2008 01:49 AM
Tree View mistry_bhavin ASP.NET 1.x and 2.0 Application Design 1 August 3rd, 2005 03:58 PM
help me on tree view gps_giri_p General .NET 0 December 13th, 2004 10:36 AM
tree view msrnivas .NET Web Services 0 February 23rd, 2004 07:04 AM
Tree View Natalie Pro VB 6 5 September 23rd, 2003 07:23 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.