473,461 Members | 1,820 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to contruct a series of treeViews

How do I contruct a series of treeViews to display a folder with subfolders and files ?? I tried but all my tries were stuck on the second subtreeView!!
how to keep the treeView going whenever there is a subfolder??
Oct 12 '09 #1
6 1836
tlhintoq
3,525 Expert 2GB
Please provide the relevant code you have mostly working and we'll see what we can do to help you fix it up.

Have you looked at the MSDN tutorial for this common need?

You'll notice that the "GetDirectories()" method calls the "GetDirectories()" method. It calls itself. This is commonly known as 'recursive'.

Basically it gets a list of files and folders.
For each folder it finds, it calls itself to get a list of files and folders...
For each folder it finds, it calls itself to get a list of files and folders...
For each folder it finds, it calls itself to get a list of files and folders...
For each folder it finds, it calls itself to get a list of files and folders...

Each file and folder become a node of the treeview.
Each node can contain another node, which represents the next hierarchy of folder.
Oct 12 '09 #2
Expand|Select|Wrap|Line Numbers
  1. private void Form1_Load(object sender, EventArgs e)
  2.         {
  3.  
  4.  
  5.             string[] m = Directory.GetDirectories(@"C:\KeysFolder");
  6.  
  7.             for (int cc = 0; cc < m.Length; cc++)
  8.             {
  9.  
  10.                 DirectoryInfo FolderName = new DirectoryInfo(m[cc]);
  11.                 string[] p = Directory.GetFiles(m[cc]);
  12.                 treeView1.Nodes.Add(FolderName.Name);
  13.  
  14.  
  15.  
  16.                 //===============================================================
  17.             }
  18.  
  19.             foreach (TreeNode tn in treeView1.Nodes)
  20.             {
  21.                 string[] bb = Directory.GetFiles(@"C:\KeysFolder\" + tn.Text); 
  22.                 foreach (string c in bb)
  23.                 {
  24.                     FileInfo jj = new FileInfo(c);
  25.                     tn.Nodes.Add(c);
  26.                 }
  27.             }
  28.  
  29.         }
the result is getting the files only in subfolders excluding the subfolders, but also, the result shows me the files in all folders in the first folder. With second folder, shows the files of in all other folders but the first folder. in the third folder, the result shows all files of the other folders but the first and the second, and so on !!!
Oct 12 '09 #3
the result is getting the files only in subfolders excluding the subfolders of the subfolders, but also, the result shows me the files in all folders in the first folder. With second folder, shows the files of in all other folders but the first folder. in the third folder, the result shows all files of the other folders but the first and the second, and so on !!!
Oct 12 '09 #4
tlhintoq
3,525 Expert 2GB
TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.
Oct 12 '09 #5
tlhintoq
3,525 Expert 2GB
You're kind working it backwards... Doing your "foreach" loop based on each treenode instead of on each file or folder found in your target folder.

It's a good attempt and shows one possible way of doing it, but not the easiest to follow and very prone to error as you've already found out.

Take a look at the MSDN tutorial I gave you a link to. Don't try to do the tracking yourself in the treenodes. The treenodes are the end result of the files and folders, not the other way around.
Oct 12 '09 #6
Thanks tlhintoq, I found my way out...
Oct 13 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Gurudev | last post by:
Is it possible to create an explorer style drag and drop for treeviews in C# i.e. the selected node text appears and moves along with the cursor while dragging thanks in advance --...
3
by: sho_nuff | last post by:
Hello all, I want to create a List of TreeViews in either a ListView or ListBox component. The result would be a list object that for the first row has a tree like: com -foo
4
by: Michael C# | last post by:
I have a quick question, and was just wondering if anyone knew a good resource, article(s) or sample source code. I want to be able to connect the nodes of two treeviews graphically via lines. I...
1
by: emferrari | last post by:
Hi everybody I have two treeviews, one of them is only to receive items dragged from the treeview1. I want to know how to drag a full node information to the treeview2. I know how to do that...
3
by: Woody Splawn | last post by:
I have been experimenting with Auto Slides and TreeViews and find them most usefull in Winforms. I know how to create a Treview and have it, for example, slide out from the left of my Winform but...
1
by: jotaefe | last post by:
Hi there, Anybody knows if it is possible to highlight nodes on a treeview (over) on a drag and drop operation from a different treeview? The two treeviews are in the same Windows form. Your...
3
Raventara
by: Raventara | last post by:
Hi-a all, I have two treeviews on a form (VB.NET) and one of them contains words, and the other commands. Each word has a command assigned to it. I chose to show this in a treeview as certain words...
0
by: track | last post by:
I have two treeviews say TreeviewA and TreeviewB on windows form in .Net. I want to transfer node from TreeviewA to TreeviewB based on selected node under TreeviewB. But problem is when I select...
4
by: furfey | last post by:
Is it possible to take an if contruct like this: if ($mmaaccess == "yes") { print "<img src='images/mma.jpg'>"; } else { print "<img src='images/oa.gif'>"; } and turn the whole thing into a...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.