7
Answers

Add to treeView not working

Ask a question
wow

wow

14y
4k
1
Hi there,

I can't get the line that was read from the file added to my treeview.  So here is what my code is doing.  It reads through a file line by line and adds a line at a time into my treeview.  My code runs through with no error. 

+ tree
 |___ node1
        |___ line   < line should be inserted here, but not working >

Any help or pointers is greatly appreciated.

 StreamReader sr = new StreamReader(somefile);

while(line = sr.ReadLine() != null)
{
TreeNode tn = new TreeNode();
tn.text = line;

MessageBox.Show(line); // Test to see if it reaches here and what the node before adding.

treeView1.Nodes[0].Nodes[0].Nodes.Add(tn);
}


Answers (7)