473,396 Members | 1,987 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Treeview and listview showing hierarchical folder system

Hi there!

I would like to ask for some help.
I'm making a little application what is a modding tool, so in the main window it has a treeview and a detailed list view to show files what can be modded. But I just can't get around this, as I would need the treeview show all folders located under a given folder hierarchically, and the listview to show files and folders from the currently selected folder in the treeview. After doing some google searches, I found nothing. Could someone help me?
Feb 27 '10 #1
4 4881
tlhintoq
3,525 Expert 2GB
After doing some google searches, I found nothing
http://www.lmgtfy.com/?q=C%23+treevi...-c1&aql=&oq=r+


http://msdn.microsoft.com/en-us/libr...45(VS.80).aspx
Feb 27 '10 #2
Thanks for it, I found the MSDN way a bit too "hacky", so I used another code:

Expand|Select|Wrap|Line Numbers
  1. public void PopulateTree(string dir, TreeNode node)
  2.         {
  3.             DirectoryInfo directory = new DirectoryInfo(dir);
  4.             foreach(DirectoryInfo d in directory.GetDirectories()) 
  5.             {
  6.                 TreeNode t = new TreeNode(d.Name);
  7.                 PopulateTree(d.FullName, t);
  8.                 dirView.Nodes.Add(t);
  9.             }
  10.         }
Feb 27 '10 #3
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.
Feb 27 '10 #4
tlhintoq
3,525 Expert 2GB
Way too hacky? Looks like virtually the same recursive loop to me.


Expand|Select|Wrap|Line Numbers
  1. private void GetDirectories(DirectoryInfo[] subDirs, 
  2.     TreeNode nodeToAddTo)
  3. {
  4.     TreeNode aNode;
  5.     DirectoryInfo[] subSubDirs;
  6.     foreach (DirectoryInfo subDir in subDirs)
  7.     {
  8.         aNode = new TreeNode(subDir.Name, 0, 0);
  9.         aNode.Tag = subDir;
  10.         aNode.ImageKey = "folder";
  11.         subSubDirs = subDir.GetDirectories();
  12.         if (subSubDirs.Length != 0)
  13.         {
  14.             GetDirectories(subSubDirs, aNode);
  15.         }
  16.         nodeToAddTo.Nodes.Add(aNode);
  17.     }
  18. }
Feb 27 '10 #5

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

Similar topics

2
by: Aron Henning | last post by:
I have a ListView that contains the subfoldes of a local drive. Whan i click on a subfolder the listbox should display the subfolders of this folder instead. the funktion is as follows: private...
2
by: Trond Hoiberg | last post by:
Let say i have a bunch of files. Logfiles that is stored in subfolders. Folder1 --logfile1 --logfile2 --logfile3 Folder2 --logfile1 --logfile2 I want to display these files using data from...
0
by: Björn Bengtsson | last post by:
Hello! I have an urgent problem concerning ASP.NET, ADO.NET, SQL Server, XML and the TreeView control. I have two tables; one describing the products and one describing their relationships. A...
7
by: vsiat | last post by:
I am trying to create a treeview out of a database table with the typical structure ID, NAME, PARENTID, TYPE, EXTRA_INFO, where is linked to the . What I want to achieve is create a tree made...
0
by: Andre Viens | last post by:
Hello, I have a TreeView I'm using to navigate through various options shown in a ListView. I want to use the SelectedNode.Tag property to hold the items in my ListView. Everything is working...
6
by: Beginner | last post by:
Hi, I'm trying to populate a TreeView from an existing and filled in ListView (lvwBuild). lvwBuild is a basic two column listview which can have any number of rows. I would like the first...
8
by: Matt MacDonald | last post by:
Hi All, I have a form that displays hierarchical categories in a treeview. Ok so far so good. What I was to do is have users be able to select a node in the treeview as part of filling out the...
2
by: Peter | last post by:
Hi, I have a problem with Listview using checkboxes. If i check items by code BEFORE the form is shown the Listview.Items are confused during the ItemChecked Event !!! After showing the...
0
by: divya1949 | last post by:
Create a windows c# application which will Read a xml file and populate nodes in the treeview. 1 On selection of treenode display the child nodes of that node in listview control 2. ...
0
by: MrColeyted | last post by:
I am designing an app that is similar to Windows Explorer. I have all working well. By clicking a directory in the treeview, the folders and files for that directory are displayed in the listview....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
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...

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.