[Resolved] TreeView AfterLabelEdit problem
I need to know when a node has been renamed and then save the new name. If I use AfterLabelEdit event it has still got the old name of the node. Has anyone got a solution for this?
VB Code:
Private Sub tvTreeView_AfterLabelEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.NodeLabelEditEventArgs) Handles tvTreeView.AfterLabelEdit
MessageBox.Show(e.Label)
End Sub
Re: TreeView AfterLabelEdit problem
I just tested it and e.Node.Text contains the old value and e.Label contains the new value. If that doesn't happen in your app then that's just weird.
Re: TreeView AfterLabelEdit problem
You are right! That is the way it works.
What I am trying to do is this:
VB Code:
Private Sub tvTreeView_AfterLabelEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.NodeLabelEditEventArgs) Handles tvTreeView.AfterLabelEdit
Call WriteConfigFile()
End Sub
Where the WriteConfigFile sub is saving the tree to a file, but from that sub I can only reach the old value.
Re: TreeView AfterLabelEdit problem
You may want to pass the old an new values to the sub that way you can make the proper changes when writing the file. When you catch that event, the new label hasn't been applied yet and thus the reason you cannot get the file to write the proper values.
Modify the WriteConfigFile() sub to check for that old value and substitute the new value is my suggestion.
Re: TreeView AfterLabelEdit problem
Thanks tacoman667, that is a good suggestion but this is only one of many times I use the WriteConfigFile() sub and in the others I don“t have this problem. So I would rather not modify the WriteConfigFile() sub. Any other suggestion?
Re: TreeView AfterLabelEdit problem
Do an overloads sub for WriteConfigFile() that way you can use that one to pass those arguments into. As far as I know there is NO way to get past the fact that the node.text is not changed when that event is fired off. That event is for if you want to validate the information before it applies, that way you can cancel the edit.
Re: TreeView AfterLabelEdit problem