edit Treenode after expand

Y

yzhao

I would like to put a treenode into edit mode right after its parent is
expanded, i.e., a user clicks the plus sign of a parent node, after the
expansion, put the first node into edit mode. I called BeginEdit() in
the AfterExpand event handler but the node won't go into edit mode. It
seems EndEdit() gets called right away! If I put BeginEdit() in a
event handler of some other control, say a context menu item, then it
worked. It's weird.

Here is a snapshot of my code:

private void treeView1_AfterExpand(object sender,
System.Windows.Forms.TreeViewE­ventArgs e)
{
this.treeView1.LabelEdit = true;
TreeNode firstNode = e.Node.FirstNode;


// put the first node into edit mode
if(!firstNode.IsEditing)
{
this.treeView1.SelectedNode = firstNode;
this.treeView1.SelectedNode.Be­ginEdit();
}
}


private void treeView1_AfterLabelEdit(objec­t sender,
System.Windows.Forms.NodeLabel­EditEventArgs e)
{
this.treeView1.LabelEdit = false;
}

Does anybody has similar problem? Any advice is appreciated.

YZhao
 
Y

yzhao

I got a workaround for this. My colleague advised me to start a timer
on the expand event and then in the tick event handler for the timer,
put the node into edit mode. That works great.

YZhao
 

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