[Gtk-sharp-list] Treeview help

Fredrik Nilsson jymdman at home.se
Fri Nov 11 11:40:55 EST 2005


Hi,

Just add a int value to the treemodel you use.
Don't know if you use treestore or liststore, but something like this:

model = new TreeStore (typeof (string), typeof (int));

where the string is the name, and the int is the contact_id.


Then in the callback you get the id like this:

int contact_id = (int)model.GetValue (iter, 1);

Hope this helps!

/Fredrik


fre 2005-11-11 klockan 09:10 -0700 skrev Clark Endrizzi:
> Hi guys,
> I've tried to go everywhere for an answer on this (except here!).  I
> am starting gnome development with mono, so I have no previous gtk
> experience and I'm trying to figure out how I can do what I need with
> treeview. 
> 
> I'm writing a simple address book app ala Mac OS X's address book and
> am pretty far along.  Basically it has two paines, the left side with
> a list of names (using treeview) and the right side displaying the
> selected name's contact information.  On the left side I only show the
> names of each contact.  When it's selected I'm using this chunk of
> code (copied from monodoc's documentation): 
> 
>    this.Selection.Changed += OnSelectionChanged;
>    // code in between
>    protected void OnSelectionChanged (object o, EventArgs args)
>    {
>            TreeIter iter;
>            TreeModel model;
>            
>            if (((TreeSelection)o).GetSelected(out model, out iter))
>            {
>                    this.currentSelection = (string)model.GetValue
> (iter, 0);
>                    Console.WriteLine ("{0} was selected",
> this.currentSelection);
>            }
> 
> this.mainWindowAccessor.ChangeContactByName(this.currentSelection);
>    }
> 
> This tells me when one is selected, giving me that contracts name as
> shown in the treeview.
> 
> It works nice for getting the selected name but as in just about any
> database app, it would be much more useful to have a way of retrieving
> the contact_id when I select a name (since the possibility exists of
> having a duplicate name, etc).  I do web development so I'm used to
> having a select widget that I can define each option like so: <option
> value="22">Name</option>.  This allows me to dispaly "Name" but it
> returns the id "22" when selected.  I know treeview is much more
> advanced than the simple HTML select widget but can I achieve this
> same thing using treeview. 
> 
> I would really appreciate any help on this since it's basically
> preventing me from going any further with this app (and my mono
> learning in general).
> 
> Thanks much in advance!
> -- 
> -Clark Endrizzi
> _______________________________________________
> Gtk-sharp-list maillist  -  Gtk-sharp-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/gtk-sharp-list



More information about the Gtk-sharp-list mailing list