Jalkhov
New member
- Joined
- Mar 24, 2021
- Messages
- 3
- Programming Experience
- 3-5
I have the following code
	
	
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
I got from here. It is to pass a directory to a Treeview object, it works fine and gives as a result something like this:
I would like to know how I can prevent the parent node, in this case Main folder, from being shown, and how to keep it like this:
Basically I only want to display the contents of the directory in question.
	
		
			
		
		
	
				
			
			
				C#:
			
		
		
		private void ListDirectory(TreeView treeView, string path)
{
    treeView.Nodes.Clear();
    var rootDirectoryInfo = new DirectoryInfo(path);
    treeView.Nodes.Add(CreateDirectoryNode(rootDirectoryInfo));
}
private static TreeNode CreateDirectoryNode(DirectoryInfo directoryInfo)
{
    var directoryNode = new TreeNode(directoryInfo.Name);
    foreach (var directory in directoryInfo.GetDirectories())
        directoryNode.Nodes.Add(CreateDirectoryNode(directory));
    foreach (var file in directoryInfo.GetFiles())
        directoryNode.Nodes.Add(new TreeNode(file.Name));
    return directoryNode;
}
└───Main folder
    ├───One folder
    │   ├───Config.example
    │   ├───DB
    │   │   └───example.sqlite
    │   └───Style
    │       └───estyles.example
    ├───Other folder
    └───Another folder
I would like to know how I can prevent the parent node, in this case Main folder, from being shown, and how to keep it like this:
One folder
├───Config.example
├───DB
│   └───example.sqlite
└───Style
    └───estyles.example
Other folder
Another folder
Basically I only want to display the contents of the directory in question.
			
				Last edited by a moderator: 
			
		
	
								
								
									
	
		
			
		
		
	
	
	
		
			
		
		
	
								
							
							 
	 
 
		 
 
		 
 
		