ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I want to create a table to display the data in a mysql's table.
The "Dev Help" tells that the GtkTreeView can make it. I tried it, but I runned into a problem. I donnot know how to add items to the list.
static void setup_tree_view (GtkWidget*);
int main (int argc,
char *argv[])
{
GtkWidget *window, *treeview, *scrolled_win;
GtkListStore *store;
GtkTreeIter iter;
guint i = 0;
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), "Grocery List");
gtk_container_set_border_width (GTK_CONTAINER (window), 10);
gtk_widget_set_size_request (window, 250, 175);
treeview = gtk_tree_view_new ();
setup_tree_view (treeview);
/* Create a new tree model with three columns, as string, gint and guint. */
store = gtk_list_store_new (COLUMNS, G_TYPE_BOOLEAN, G_TYPE_INT, G_TYPE_STRING);
/* Add all of the products to the GtkListStore. */
while (list[i].product != NULL)
{
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter, BUY_IT, list[i].buy,
QUANTITY, list[i].quantity, PRODUCT, list[i].product, -1);
i++;
}
/* Add the tree model to the tree view and unreference it so that the model will
* be destroyed along with the tree view. */
gtk_tree_view_set_model (GTK_TREE_VIEW (treeview), GTK_TREE_MODEL (store));
g_object_unref (store);
scrolled_win = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win),
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_container_add (GTK_CONTAINER (scrolled_win), treeview);
gtk_container_add (GTK_CONTAINER (window), scrolled_win);
gtk_widget_show_all (window);
gtk_main ();
return 0;
}
/* Add three columns to the GtkTreeView. All three of the columns will be
* displayed as text, although one is a gboolean value and another is
* an integer. */
static void setup_tree_view (GtkWidget *treeview)
{
GtkCellRenderer *renderer;
GtkTreeViewColumn *column;
/* Create a new GtkCellRendererText, add it to the tree view column and
* append the column to the tree view. */
renderer = gtk_cell_renderer_text_new ();
column = gtk_tree_view_column_new_with_attributes
("Buy", renderer, "text", BUY_IT, NULL);
gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
renderer = gtk_cell_renderer_text_new ();
column = gtk_tree_view_column_new_with_attributes
("Count", renderer, "text", QUANTITY, NULL);
gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
renderer = gtk_cell_renderer_text_new ();
column = gtk_tree_view_column_new_with_attributes
("Product", renderer, "text", PRODUCT, NULL);
gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
}
static void setup_tree_view (GtkWidget*);
int main (int argc,
char *argv[])
{
GtkWidget *window, *treeview, *scrolled_win;
GtkListStore *store;
GtkTreeIter iter;
guint i = 0;
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), "Grocery List");
gtk_container_set_border_width (GTK_CONTAINER (window), 10);
gtk_widget_set_size_request (window, 250, 175);
treeview = gtk_tree_view_new ();
setup_tree_view (treeview);
/* Create a new tree model with three columns, as string, gint and guint. */
store = gtk_list_store_new (COLUMNS, G_TYPE_BOOLEAN, G_TYPE_INT, G_TYPE_STRING);
/* Add all of the products to the GtkListStore. */
while (list[i].product != NULL)
{
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter, BUY_IT, list[i].buy,
QUANTITY, list[i].quantity, PRODUCT, list[i].product, -1);
i++;
}
/* Add the tree model to the tree view and unreference it so that the model will
* be destroyed along with the tree view. */
gtk_tree_view_set_model (GTK_TREE_VIEW (treeview), GTK_TREE_MODEL (store));
g_object_unref (store);
scrolled_win = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win),
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_container_add (GTK_CONTAINER (scrolled_win), treeview);
gtk_container_add (GTK_CONTAINER (window), scrolled_win);
gtk_widget_show_all (window);
gtk_main ();
return 0;
}
/* Add three columns to the GtkTreeView. All three of the columns will be
* displayed as text, although one is a gboolean value and another is
* an integer. */
static void setup_tree_view (GtkWidget *treeview)
{
GtkCellRenderer *renderer;
GtkTreeViewColumn *column;
/* Create a new GtkCellRendererText, add it to the tree view column and
* append the column to the tree view. */
renderer = gtk_cell_renderer_text_new ();
column = gtk_tree_view_column_new_with_attributes
("Buy", renderer, "text", BUY_IT, NULL);
gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
renderer = gtk_cell_renderer_text_new ();
column = gtk_tree_view_column_new_with_attributes
("Count", renderer, "text", QUANTITY, NULL);
gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
renderer = gtk_cell_renderer_text_new ();
column = gtk_tree_view_column_new_with_attributes
("Product", renderer, "text", PRODUCT, NULL);
gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
}
[\code]
Wow ... Now thats what I call "going out of your way to help someone!"
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.