Using BeginEdit and EndEdit to edit treenode labe.

Hello!

I've got a treeview and a button. When I click the button a new treenode is added to the selected treenode in the treeview. When added I want it to imedietly go into edit mode so the user can write the label. I do this by just running newNode.BeginEdit(); This works. BUT, when I'm done editing and I hit ENTER the label gets blank and I end up with an empty label.

I've added e.Node.EndEdit(false) to the AfterLabelEdit event of the treeview but i still get the same empty label.

Any ideas what I'm doing wrong?

(I'm using C#)

[556 byte] By [Marlun] at [2007-12-16]
# 1
I had no problems with the following:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim tn As TreeNode = TreeView1.SelectedNode.Nodes.Add("")
tn.EnsureVisible()
tn.BeginEdit()
End Sub

-mark
TreeView Program Manager
Microsoft
This post is provided "as-is"

MarkRideout at 2007-9-9 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 2
Hello!
Works good, thanks for the answer! but...
I believe this works because you give the new node a empty label "", I only did like:
TreeNode tn = new TreeNode();
parentNode.Nodes.Add(tn);
tn.BeginEdit();

Could that be the problem, and if so, why is that?
Another thing, I thought the one who wrote the question were the only one who could mark answers as "answers"? Not that your answer wasn't a good answer but I'm only curious.
Thanks again!

Marlun at 2007-9-9 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 3

Yes - that is the problem. Looks like a bug that has been around since 1.0. Providing the empty label is the correct workaround.

-mark
Program Manager
Microsoft
This post is provided "as-is"

MarkRideout at 2007-9-9 > top of Msdn Tech,Windows Forms,Windows Forms General...