GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Wed Jul 30, 2014 12:57 am

All times are UTC




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: regarding gtktreeview
PostPosted: Mon Apr 02, 2007 5:35 am 
Offline
GTK+ Geek

Joined: Fri Oct 06, 2006 6:37 am
Posts: 57
hi
iam using gtktreeview with only one column
in this i added gtkliststore to gtk treeview
how can get the selecteed row and row number.
give me some sample code
thank u
sree


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 02, 2007 11:14 am 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 3:07 am
Posts: 384
Location: Fairfax, Virginia
Code:
GtkTreeModel *model; /* Your GtkListStore cast as a tree model. */
GtkTreeIter iter; /*This will point to the row. */
gint x; /* The row number. Remember that row 1 is #0. */

/* The parent row iterator is set to NULL so that the root is used. */
if (gtk_tree_model_iter_nth_child (model, &iter, NULL, x)
{
  /* Use iter, which points to row x. */
}

_________________
Andrew Krause

Foundations of GTK+ Development: Buy now for only $31.49!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 03, 2007 5:33 am 
Offline
GTK+ Geek

Joined: Fri Oct 06, 2006 6:37 am
Posts: 57
i tried like this

g_signal_connect ((gpointer) G_ContactList, "cursor-changed",
G_CALLBACK (Contacts_Buddy_Clicked),
NULL);

void Contacts_Buddy_Clicked(GtkWidget *widget,gpointer user_data)

{

gint x;

if(gtk_tree_model_iter_nth_child (store1, &iter, NULL, x));
g_print ("selected row is: %d\n",x);
}


but it's printing aa garbage value like 1865384
.
thank u
sree


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 03, 2007 8:37 am 
Offline
Familiar Face

Joined: Tue Feb 13, 2007 3:45 pm
Posts: 30
Location: Madrid, Spain
Dumb question:

Is 'x' initialized?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 03, 2007 11:13 am 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 3:07 am
Posts: 384
Location: Fairfax, Virginia
It's not a dumb question. That's his problem in that code. You must initialize x to the row you want to select.

_________________
Andrew Krause

Foundations of GTK+ Development: Buy now for only $31.49!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 04, 2007 4:20 am 
Offline
GTK+ Geek

Joined: Fri Oct 06, 2006 6:37 am
Posts: 57
how we can intalize
i need the row number which i selected the row in runtime gtktreeview
thank u
sree


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 04, 2007 11:49 am 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 3:07 am
Posts: 384
Location: Fairfax, Virginia
You get the GtkTreeSelection from your tree view with gtk_tree_view_get_selection. Then use, gtk_tree_selection_get_selected(), which will retrieve the tree view's model and an iterator pointing to the selected row.

_________________
Andrew Krause

Foundations of GTK+ Development: Buy now for only $31.49!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 05, 2007 4:29 am 
Offline
GTK+ Geek

Joined: Fri Oct 06, 2006 6:37 am
Posts: 57
thank u
but i need roe number .
how can get row number from iterator.
thank u
sree


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 05, 2007 11:05 am 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 3:07 am
Posts: 384
Location: Fairfax, Virginia
Code:
GtkTreePath *path = gtk_tree_model_get_path (model, &iter);
gint *ind = gtk_tree_path_get_indices (path);


If you are using GtkTreeStore, this will return a list of row numbers with respect to each parent node. If you use GtkListStore, just use *ind to dereference to get the row number indexed from 0.

_________________
Andrew Krause

Foundations of GTK+ Development: Buy now for only $31.49!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group