0

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..

1
Contributor
1
Reply
6
Views
5 Years
Discussion Span
Last Post by bhagyap
0

I have achieved the above requirement as follows:-

    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)
    {

        //string directory = opt.checkedListBox1.CheckedItems.ToString();
        foreach (var obj in opt.checkedListBox1.CheckedItems)
        {
            ListDirectory(treeView1, "E:\\mails\\" + obj);
            treeView1.ExpandAll();
        }

    }

But am unable to loop it for all checked folders,please guide me where am going wrong??

Edited by Dani: Formatting fixed

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.