1
Answer

Tree View Problem

Vivekh

Vivekh

14y
2k
1
Hi all i have written my code to display list of files

 private void treeView1_Click(object sender, EventArgs e)
        {
            string strFiletype;
            //path += "fileheader*.txt";
            string[] fileEntries = Directory.GetFiles(path, "fileheader*.txt");
            foreach (string fileName in fileEntries)
            {
                strFiletype = fileName.Substring(fileName.IndexOf("fileheader"));
                treeView1.Nodes.Add(new TreeNode(strFiletype));

                // myTreeNode myNode = (myTreeNode)e.Node;
                // MessageBox.Show("Node selected is " + myNode.FilePath);

            }
        }

But on clicking nodes file are getting appended automatically for multiple times.

And i need another help

My tree view is like this

Root
|-> Child0
|->Child

If i click on Child0 i would like to display  the file names under this ..

And whem i am writing this myTreeNode myNode = (myTreeNode)e.Node;

i am getting an error as


Unable to cast object of type 'System.Windows.Forms.TreeNode' to type 'myTreeNode'.


Please can any one modify this and send me
Answers (1)
Next Recommended Forum