Frist see following code and images.
Code A
treeView1.Nodes.Add("Node A");
treeView1.Nodes.Add("Node B");
Output :

Code B
TreeNode tn = new TreeNode();
tn.Nodes.Add("Node A");
tn.Nodes.Add("Node B");
treeView1.Nodes.Add(tn);

Now my problem is that treeView1.Nodes.Add(tn); creating a blank node, but my requirement is like Code A's image type (without blank node). If you need any other information please let me know.
UPDATE
Actually Ithere is a function in my code which returns a TreeNode and I have to add this node to TreeView control without first blank level.
This code:
TreeNode tn = new TreeNode();
creates an actual item. You didn't give it any text, so it appears blank. Then next two lines are adding child nodes to the blank node.
If your goal is the code in "A", why are you writing "B"?
Edit: response to your updated question
You have a function returning a root blank tree node, which contains children you want. So, something like this is in order.
foreach (var node in returnedNode.Nodes)
{
treeView1.Nodes.Add(node);
}
OR
treeView1.Nodes.AddRange(returnedNode.Nodes.Cast<TreeNode>().ToArray());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With