Maurice Freitag Maurice Freitag - 3 months ago 12
C# Question

TreeNode BeginEdit() doesn't save any text

I added a treeview to my main form, right-clicking opens a contextmenu where you can add new nodes to the tree (in this case categories).

It creates, then adds the node and calls BeginEdit()...

private void addCategoryToolStripMenuItem_Click(object sender, System.EventArgs e)
{
var category = new TreeNode();

tvCategories.Nodes.Add(category);
category.BeginEdit();
}


...and then this:

From the info I gathered this should work just fine, howeeeeever:

enter image description here
Any ideas? :)

Just a kind of extension: the problem doesn't lie within BeginEdit(), I can't edit the label at all. I still don't know why, but now I know I need to look somewhere else.

Answer

Your initial node can't be blank, so fill it with some kind of text:

var category = new TreeNode("abc");