日期:2014-05-16 浏览次数:20890 次
/* 把名字和分数组合成结构体,方便你用指针操作 */
typedef struct
{
gchar *name;
gint score;
}
Student;
gint i = 0;
GtkListStore *model;
GtkTreeIter iter;
array = g_array_sized_new (FALSE, FALSE, sizeof (Student), 1);
/* create list store */
model = gtk_list_store_new (NUM_ITEM_COLUMNS, G_TYPE_INT, G_TYPE_STRING,
G_TYPE_INT, G_TYPE_BOOLEAN);
/* 想通过名字获取分数的话,你需要得到array和i,当然,你已经知道名字了 */
for (i = 0; i < array->len; i++)
{
gtk_list_store_append (model, &iter);
/* 这里是设置,获取的原理是一样的 */
gtk_list_store_set (model, &iter,
g_array_index (array, Student, i).name,
g_array_index (array, Student, i).score,
-1);
}
/*
* 关于删除也一样,需要知道iter,GTK只有两种删除,
* 一个是删除全部,另一个是删除一行
*/
/* iter要和tree配合,我这里没写 */
if (gtk_tree_selection_get_selected (selection, NULL, &iter)){
gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
}
/* Removes the given row from the list store. After being removed, iter is set to be the next valid row, or invalidated if it pointed to the last row in list_store */
gboolean gtk_list_store_remove(GtkListStore *list_store, GtkTreeIter *iter);
/* Removes all rows from the list store */
void gtk_list_store_clear(GtkListStore *list_store);