Re: Bind GtkTreeView row to some object

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Nov 26, 2014 at 10:59:01PM +0100, John Tall wrote:
> Hello.

Hi.

> I have a GtkTreeView that is used to display some data. Let's say that
> I have a class that defines a person, and that I have a number of
> objects representing different persons. I want to display the name of
> each person in the tree view so I add a row for each person and set
> the value of the first column to the name of the person.
> 
> GtkTreeIter iter;
> GtkListStore *store = ...;
> 
> gtk_list_store_append (liststore, &iter);
> gtk_list_store_set (liststore, &iter, 0, x_person_get_name (person), -1);
> 
> This works fine. But let's say that I want to select a row in the tree
> view and show a dialog with more information on the person. So I
> connect to the row-activated signal and implement the callback. But
> this is where I need a way to get that person object back. I can't
> look up the object based on the name of the person, because there can
> be multiple persons with the same name.
> 
> Is it possible to bind a row in the tree view, or I guess technically
> the list store, to my object so that I can figure out which object the
> row represents?

I don't know of any built-in way to bind a row to a particular object,
apart from adding a pointer to it in an additional column in the list
store and never include that column in the UI.

Another possibility would be to use the GtkTreePath that you get in the
row-activated signal handler as an index, assuming that you have your
objects stored in for example an array. The tree path will contain the
index from the tree view, so make sure you convert it to its original
first if your tree view supports sorting and filtering.

		Marcus
_______________________________________________
gtk-list mailing list
gtk-list@xxxxxxxxx
https://mail.gnome.org/mailman/listinfo/gtk-list




[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux