Click here to Skip to main content
15,314,186 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi..

I am populating a treeview in form1 based on the checkeditems in checkedlistbox which is in form2 but am unable to list the subfolders and files of the checked folder..

Can anyone please help me????

Thanks..
Posted

Your question is not very clear.
If you are looking to display folder structures in a treeview, go through
C# File Browser[^]
Enhanced BrowseForFolder styled TreeView[^].

Here[^] is a simpler example that can help you get started.
   
Comments
bhagyap 10-Dec-11 3:13am
   
According to my requirement i have two forms form1 and form2,in form1 i have an treeview and in form2 i have checkedlistbox which i am populating as follows:-

System.IO.DirectoryInfo di = new System.IO.DirectoryInfo("E:\\Mails");
System.IO.FileSystemInfo[] files = di.GetDirectories();
checkedListBox1.Items.AddRange(files);

and based on the checkedfolder i am building an treeview but am unbale to view the subfolders and files from the checked folder..

Please guide me..

Thanks..
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;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            foreach (var obj in opt.checkedListBox1.CheckedItems)
            {
                ListDirectory(treeView1, "E:\\mails\\" + obj);
               
                treeView1.ExpandAll();
            }

        }

I hav achieved the above as follows but am unable to loop for all the checked folders.. please guide me where am going wrong???
   
v2
Hi,

You can call function on click on tree node, once the node event fire, you can check for the new path and generate the new sub node, I have done and it worked

if you want I can share the same with you

Thanks,
Nik Varma
   
Comments
Deepu S Nair 3-May-15 8:20am
   
?You can see that the question is nearly 5 years old and already solve.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900