what code is make to treeview node expand

67 views Asked by At

enter image description here

private void Form1_Load(object sender, EventArgs e)
{   
    foreach (DriveInfo drv in DriveInfo.GetDrives())
    {
        if (drv.IsReady)
        {
            TreeNode t2 = new TreeNode();
            t2.Text = drv.Name;
            t2.Nodes.Add("");
            treeView.Nodes.Add(t2);
        }
    }
}

parent node don't expand to child node how can i fix it?

1

There are 1 answers

0
Jim On

If you want to expand all nodes you can use the TreeView.ExpandAll() method

private void Form1_Load(object sender, EventArgs e)
{   
    foreach (DriveInfo drv in DriveInfo.GetDrives())
    {
        if (drv.IsReady)
        {
            TreeNode t2 = new TreeNode();
            t2.Text = drv.Name;
            t2.Nodes.Add("make this not empty to show a result");
            treeView.Nodes.Add(t2);

            treeView.ExpandAll();
        }
    }
}