views:

1870

answers:

3

I am playing with Microsoft's TreeView control and I am trying to force a data update of some sorts while editing a node's label, similar to UpdateData for a grid.

Basically, in my editor, I have a Save button and this TreeView control: what I want is when I am editing a node's label in the TreeView, if I click on the Save button I want to be able to commit the node's label I was editing.

A: 

The node label editing is performed with a text box and when that text box loses focus the change in name will be committed as the new label for the node. So if the 'Save' button you are clicking on takes the focus then it will cause the update automatically because the text box will lose focus.

If the 'Save' button does not take focus then need to handle a click event for the 'Save' button and ask the tree to end any current label editing. If does not have a method/property you can call to request label editing finish so you have two choices. If the tree view has the focus then put the focus somewhere else. Alternatively turn off/on again label editing...

treeView.LabelEdit = false;
treeView.LabelEdit = true;
Phil Wright
A: 

I'll accept the answer even though it's not really documented: does it or does it not have such a method? You actually didn't answer to this, just passed the question back to me.

Meanwhile found the same hack-ish solution with forcing the focus to some other control (not very elegant but works), even though it's a bit harder for me since I use a TreeView as part of a UserControl.

Horas
A: 

Do you really need a save button?

you could listen for the end of the node edit - for instance by listening for the "return" key in the KeyDown event of the TreeView. if you're editing something (find out with SelectedNode.IsEditing) then you know you have a commit. You can then commit this to your dataupdate stuff. If you want to be able to edit many different nodes and save them all at the end, then you need to add each edited node to a collection of some sort, and then when you click your save button iterate through this collection.

Matt Jacobsen