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

Re: Listbox, Treeview and attaching pointers to rows



Damien Caliste wrote:
Hello,

Le 24/10/2007, Arto Karppinen <exeonical mail suomi net> a �it :
 Row one -> Data pointer 1
 Row two -> Data pointer 1
 Row n+1 -> Data pointer 1
How would one accomplish such amazing task?
Your data pointer should added in your model:
enum
{
	COL_LABEL,
	COL_DATA,
	NB_COLS
};

GtkListStore *list;
list = gtk_list_store_new (NB_COLS, G_TYPE_STRING, G_TYPE_POINTER);

Then, when you populate your model, store your data pointers:
for (i = 0; i < n; i++)
{
	/* Compute the values, associating a label and
           and data pointer. */
	[...]
	/* Store them in the liststore. */
	gtk_list_store_set(list, &iter,
		     COL_LABEL , label_i,
		     COL_DATA  , (gpointer)data_row_i,
		     -1);
}
You don't need to store your data pointers into a custom array, they are
stored for you in the liststore.

Finally, in your selection callback (at the iterator iter), retrieve the
stored data pointers:
gpointer data_row;
gtk_tree_model_get(GTK_TREE_MODEL(list), &iter,
                   COL_DATA, &data_row, -1);

Damien.

Thanks. This does what i want it to do.

--
Arto Karppinen
------------------------------
arto karppinen iki fi



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