79226881

Date: 2024-11-26 13:27:10
Score: 1.5
Natty:
Report link

I reviewed the code samples mentioned by @Holger, and based on them used the approach of appending string objects to a list store.

Comparison function

gint comparestrings (gconstpointer a, gconstpointer b, gpointer user_data) {
GtkStringObject *object_a = (GtkStringObject *)a;
GtkStringObject *object_b = (GtkStringObject *)b;
const char *string_a = gtk_string_object_get_string(object_a);
const char *string_b = gtk_string_object_get_string(object_b);
return g_ascii_strncasecmp (string_a, string_b, 10);
}

Instantiating the dropdown and populating with string objects

GListStore *list_store = g_list_store_new(GTK_TYPE_STRING_OBJECT);
GtkWidget *dropdown= gtk_drop_down_new(G_LIST_MODEL(list_store), NULL);
g_list_store_append(list_store,gtk_string_object_new("zebra"));
g_list_store_append(list_store,gtk_string_object_new("horse"));
g_list_store_append(list_store,gtk_string_object_new("monkey"));
g_list_store_append(list_store,gtk_string_object_new("aardvark"));
g_list_store_sort (list_store, comparestrings, NULL);

Sorts correctly as advertised.

enter image description here

Reasons:
  • Probably link only (1):
  • Long answer (-1):
  • Has code block (-0.5):
  • User mentioned (1): @Holger
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: 9-Pin