The trick is to use the Path
property of the Gtk.EditedArgs
argument passed to your event handler to get the correct node from the store and modify (you're responsible to propagate the change from the UI to your model). A small, complete example follows.
Given the following Gtk.TreeNode
implementation:
[Gtk.TreeNode]
public class MyTreeNode : Gtk.TreeNode
{
public MyTreeNode(string text)
{
Text = text;
}
[Gtk.TreeNodeValue(Column=0)]
public string Text;
}
it is easy to change the Text
property as follows:
Gtk.NodeStore store = new Gtk.NodeStore(typeof(MyTreeNode));
store.AddNode(new MyTreeNode("The Beatles"));
store.AddNode(new MyTreeNode("Peter Gabriel"));
store.AddNode(new MyTreeNode("U2"));
Gtk.CellRendererText editableCell = new Gtk.CellRendererText();
Gtk.NodeView view = new Gtk.NodeView(store);
view.AppendColumn ("Artist", editableCell, "text", 0);
view.ShowAll();
editableCell.Editable = true;
editableCell.Edited += (object o, Gtk.EditedArgs args) => {
var node = store.GetNode(new Gtk.TreePath(args.Path)) as MyTreeNode;
node.Text = args.NewText;
};
Note:
- the use of
args.Path
to get the correctMyTreeNode
from the store; and - the cast of the result to
MyTreeNode
to be able to access theText
property.