Hello,

I have a treeview that is populated with an Integer value (from a mysql 
database) that is populated into a G_TYPE_STRING. This displays 
correctly but the sort function using:
          gtk_tree_view_column_set_sort_column_id (col, x);
          gtk_tree_view_column_set_sort_indicator (col, TRUE);

sorts the values as Alphanumeric, not numeric.
ie:
12
2
3
6
7

instead of
2
3
6
7
12

Do I need to hook in a Sort function and use the Modelsort instead of Model?
Should sorting a integer value be a basic function of a treeview/liststore?
Should I be setting an attribute of the column as "integer" instead of 
"text"?

The entire function is listed here:

void populate_battle (gchar *battleid)
{
// Get Treeview and populate with all the Combatants in the Battle!
 gchar   *sql;
 MYSQL   *conx;
 MYSQL_RES *result_set;
 MYSQL_ROW db_row;
 MYSQL_FIELD *field;
 GtkListStore *list_store;
 GtkTreeModel *model;
 GtkTreeIter iter;
 GtkTreeView *treeview2;
 GtkCellRenderer *renderer; 
 GtkTreeViewColumn *col;
 GtkTreeSelection  *selection;
 gint x, MAX_BATTLE_COLUMNS = 9;
 gboolean valid;
 gchar *BATTLE_COLS[] = { "ID", "Name", "Init", "AC","Flat", "Touch", 
"HP", "Max HP", "Base Init" };

 // CREATE THE TREE_VIEW
 treeview2 = GTK_TREE_VIEW(lookup_widget(battlemaster_mainwindow, 
"treeview2"));
 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview2));
 gtk_tree_selection_set_select_function(selection, 
copy_battle_creature_func, NULL, NULL);
 model = gtk_tree_view_get_model(treeview2);
 // Clear out old Model so we can get the new one.
// gtk_list_store_clear (GTK_LIST_STORE(model));
 if (model == NULL)
 {
    // CREATE COLUMN HEADERS
    for (x=0; x< MAX_BATTLE_COLUMNS; x++)
    {
       // -- Add Column X --
       col = gtk_tree_view_column_new();
       gtk_tree_view_column_set_title(col, BATTLE_COLS[x]);
       gtk_tree_view_append_column(GTK_TREE_VIEW(treeview2), col);
       renderer = gtk_cell_renderer_text_new();
       gtk_tree_view_column_pack_start(col, renderer, TRUE);
       gtk_tree_view_column_add_attribute(col, renderer, "text", x);
       gtk_tree_view_column_set_resizable(col, TRUE);
       gtk_tree_view_column_set_expand(col, TRUE);
       if (x == 2)
       {
          gtk_tree_view_column_set_sort_column_id (col, x);
          gtk_tree_view_column_set_sort_indicator (col, TRUE);
          g_object_set(renderer, "editable", TRUE, NULL);
          g_signal_connect(renderer, "edited", (GCallback) 
init_edited_callback, NULL);

       }
       if (x == 6)
       {
          g_object_set(renderer, "editable", TRUE, NULL);
       }

   }
 }
    // Create the data storage
    list_store = gtk_list_store_new (MAX_BATTLE_COLUMNS, G_TYPE_STRING, 
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, 
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
 /* First, connect to the database. */
 conx = mysql_init(0L);
 if (conx != 0L)
 {
   conx = mysql_real_connect(conx, SERVER, USER, PASS, DBASE, 0, 0L,0);
   if (conx != 0L)
   {
    sql = g_strconcat("select c1.nameid, c1.charname, b1.init, c1.ac, 
c1.flat, c1.touch, b1.actualhp, c1.hp, c1.init from battle b1, creature 
c1 where b1.nameid = c1.nameid AND combatid = ", combat_id, " ; ", 0L);
    if (mysql_query (conx, sql) == 0)
    {
      result_set = mysql_store_result (conx);
      // ADD ONE ROW FOR EACH MYSQL ROW RETRIEVED
      while ((db_row = mysql_fetch_row (result_set)) != 0L)
      {
          gtk_list_store_append (list_store, &iter);
          // Now Fill a Row with the Data Retrieved
          gtk_list_store_set (list_store, &iter, 0, db_row[0],
             1, db_row[1],
             2, db_row[2],
             3, db_row[3],
             4, db_row[4],
             5, db_row[5],
             6, db_row[6],
             7, db_row[7],
             8, db_row[8],  -1);
      }
      mysql_close(conx);
   }
  }
  model = GTK_TREE_MODEL(list_store);
  gtk_tree_view_set_model (treeview2, model);
  g_object_unref (model);
 }
 gtk_widget_show(GTK_WIDGET(treeview2));
}


Thanks for any guidelines.....


-- 
---
Regards,

Jason Brisbane 


_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Reply via email to