TreeView expand problem

A

Adam Klobukowski

Hello

I'm trying to implement 'in place' node adding to treeview. Ie, user
requests new item and it appears in treeview reade to edit.

I have this C# code:

if (treeView1.SelectedNode != null)
{
TreeNode node = treeView1.SelectedNode;

node.Nodes.Add("");
node.Expand();

node.Nodes[node.Nodes.Count - 1].EnsureVisible();
treeView1.LabelEdit = true;
node.Nodes[node.Nodes.Count - 1].BeginEdit();
}

It works well if a node I'm adding subnode already has some nodes. It
does not work if node I'm adding subnode has no subnodes yet: after
node.Expand(), node.Nodes is empty :( (ie node.Nodes.Count == 0).

What is wrong here?
 
A

Adam Klobukowski

As usual, after sending this question, I found that my function in
BeforeExpand was causing this.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top