[Gtk-sharp-list] Gtk.Combo list

Duncan Mak duncan@ximian.com
06 Mar 2003 03:19:03 -0500

Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Hola Jorge!

On Wed, 2003-03-05 at 19:58, Jorge De Gante wrote:
> I need to populate a Gtk.Combo, I can't find any sample for gkt-sharp
> only for gtk2, and i realized that there is a Gtk.List asociated with
> the combo.

Currently, there is one way to populate a Gtk.Combo; you use the
SetPopdownStrings method, which takes "params string[] args" as its
arguments. This will work if you only populate the list once.

Sorry for not responding earlier - I tried to write a new sample in
gtk-sharp/samples/tests for you, but got sidetracked with other things.
I just committed TestCombo.cs to gtk-sharp, and you can look there if
you only want basically functionality of the ComboBox.

Your post did bring up a good point: how should we handle the Gtk.List
widget in Gtk.Combo? I talked to Kris a bit about this and we both
thought it should be best not to expose the List widget, since it's
already deprecated.

I tried to write some C and C# glue to make appending to the list
possible. I wrote the following code (patch attached), but I see this
error when I try to use my new little method:

Unhandled Exception: System.NullReferenceException: A null value was
found where an object instance was required
in (unmanaged) 06 Gtk.Combo:gtksharp_combo_append_string (intptr,intptr)
in <0x00004> 06 Gtk.Combo:gtksharp_combo_append_string (intptr,intptr)
in <0x0006f> 00 WidgetViewer.TestCombo:OnComboActivated
in <0x0007d> 01 System.MulticastDelegate:invoke_void_object_EventArgs
in <0x00164> 00 GtkSharp.voidObjectSignal:voidObjectCallback
in <0x00026> 05 GtkSharp.voidObjectSignal:voidObjectCallback
in (unmanaged) 06 Gtk.Application:gtk_main ()
in <0x00004> 06 Gtk.Application:gtk_main ()
in <0x00d34> 00 WidgetViewer.Viewer:Main ()

After reading this patch, Kris will probably laugh at my wimpish
inability to write C code ;-) I guess this NullRef comes from the fact
that combo->list might be null.

But hey, here's the patch. If anyone can figure this out, or propose a
good way to handle this, that'd be great; because we really should fix

Good night,

Duncan Mak <duncan@ximian.com>

Content-Disposition: attachment; filename=combo.patch
Content-Type: text/x-patch; name=combo.patch; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Index: gtk/Combo.custom
RCS file: /cvs/public/gtk-sharp/gtk/Combo.custom,v
retrieving revision 1.3
diff -u -p -r1.3 Combo.custom
--- gtk/Combo.custom	7 Nov 2002 19:19:38 -0000	1.3
+++ gtk/Combo.custom	6 Mar 2003 08:10:14 -0000
@@ -23,3 +23,11 @@ public Gtk.Button Button {
 		return new Gtk.Button (gtksharp_combo_get_button(this.Handle));
+static extern IntPtr gtksharp_combo_append_string (IntPtr i, IntPtr s);
+public void AppendString (string text)
+	gtksharp_combo_append_string (this.Handle, Marshal.StringToHGlobalAnsi (t=
Index: glue/combo.c
RCS file: /cvs/public/gtk-sharp/glue/combo.c,v
retrieving revision 1.2
diff -u -p -r1.2 combo.c
--- glue/combo.c	7 Nov 2002 19:19:15 -0000	1.2
+++ glue/combo.c	6 Mar 2003 08:10:14 -0000
@@ -4,6 +4,8 @@
+#include <glib-2.0/glib.h>
+#include <gtk/gtklist.h>
 #include <gtk/gtkcombo.h>
@@ -16,4 +18,14 @@ GtkWidget*=20
 gtksharp_combo_get_button (GtkCombo* combo)
 	return combo->button;
+gtksharp_combo_append_string (GtkCombo* combo, char* string)
+	GtkList *l =3D combo->list;
+	GList *list =3D l->children;
+	list =3D g_list_append (list, string);
+	gtk_combo_set_popdown_strings (combo, list);