0

I need to get node position in the Gtk.TreeView. I'm able to get the row and what the user changed, but I have to hardcore the column, is there any way how to get it?

Here's the code:

private void artistNameCell_Edited (object o, Gtk.EditedArgs args)
{
    Gtk.TreeIter iter;

    musicListStore.GetIter (out iter, new Gtk.TreePath (args.Path));

    Song song = (Song) musicListStore.GetValue (iter, 0);
    song.Artist = args.NewText;
}

It's from here http://www.mono-project.com/GtkSharp_TreeView_Tutorial , it's the editable text cells section. In the code they just select column number 0:-/, but I need whatever column user clicks. Respectively the exact Node position something like node[row,column], now I have just node[iter,0].

gpoo
  • 8,408
  • 3
  • 38
  • 53
user1086004
  • 51
  • 1
  • 4
  • possible duplicate of [How do I get the item (tree node) under the mouse pointer in a TreeView?](http://stackoverflow.com/questions/9556389/how-do-i-get-the-item-tree-node-under-the-mouse-pointer-in-a-treeview) – skolima Mar 09 '12 at 21:11
  • No, this line Item item = (Item) store.GetValue (iter, 0); again refers to first column:-/ I tried it – user1086004 Mar 09 '12 at 21:23

3 Answers3

0

you could define the event handler like this

int i = counter;
cellTextRenderer.Edited  +=( sender,  args) => {
 TreePath path = new TreePath (args.Path);
 TreeIter iter;
 musicListStore.GetIter (out iter, path);   
 //i is column number
 musicListStore.SetValue (iter, i, args.NewText);
};
Ivan Galabov
  • 1
  • 1
  • 2
0

I ran the sample program GTkDemo that comes with the Mono framework on Windows (the samples directory), and i could edit the treeview editable cells samples, i paste the code where it handles the event,

private void TextCellEdited(object o, EditedArgs args)
{
TreePath path = new TreePath(args.Path);
TreeIter iter;
store.GetIter(out iter,path);
int i = path.Indices[0];
Item foo = (Item)articles[i];
foo.Product = args.NewText;
store.SetValue (iter, (int) Column.Product, foo.Product);
}

Where store is a ListStore. I recommend you see the full source code, it comes with the Mono Framework for Windows under the [Program files(x86)]\Mono-2.10.8\samples\gtk-sharp-2.0\GtkDemo.

I hope this can helps you.

xomalli
  • 96
  • 2
0

In the GTK+ C API, you would get a reference to the CellRendererText as the first argument to your signal handler. I believe you can access this in GTK# as args.Args[0], but I'm not 100% sure of that.

I don't see an obvious way to go from a CellRendererText object to the corresponding column in your TreeStore (but I could be wrong about that). For this to be useful, you may have to make your own mapping.

An alternative would be to use a different event handler for the Edited event of each CellRendererText, and make sure that each handler knows the correct column number.

Esme Povirk
  • 3,004
  • 16
  • 24