i need to based in what the user wrote in the edition of a node label, rewrite that label with other text. Example if the user wrote "NewNodeName" I want that the node text after finish the edition be "S :NewNodeName". I try this two codes and i don't know why neither work
private void treeView1_AfterLabelEdit(object sender, NodeLabelEditEventArgs e)
{
e.Node.Text = "S :"+ e.Label;
}
and also:
private void treeView1_AfterLabelEdit(object sender, NodeLabelEditEventArgs e)
{
treeView1.SelectedNode.Text = "S :"+ e.Label;
}
Yes, doesn't work, the Text property gets the label value after this event runs. Which is why e.Cancel works. So the Text value you assigned will be overwritten again by code that runs after raising this event. Code inside of the native Windows control.
There is no AfterAfterLabelEdit event and you cannot alter e.Label in the event handler, you need a trick. Change the Text property after the event stopped running. Elegantly done by using Control.BeginInvoke(). Like this:
private void treeView1_AfterLabelEdit(object sender, NodeLabelEditEventArgs e) {
this.BeginInvoke((MethodInvoker)delegate { e.Node.Text = "S: " + e.Node.Text; });
}
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