[Gtk-sharp-list] ComboBox Items Don't Display

Jim Orcheson jim at va3hj.ca
Mon Jun 13 09:18:12 EDT 2011


Of course the final code snippet should read:

              ComboBox cb = new ComboBox();
              cb.AppendText("A");
              cb.AppendText("B");
              cb.AppendText("C");



On 11-06-13 09:15 AM, Jim Orcheson wrote:
> I am having a problem displaying items in a ComboBox. See the sample
> program below:
>
> using System;
> using Gtk;
> namespace ComboBoxTest
> {
>       public class CombBoxTest
>       {
>           public static void Main()
>           {
>               Application.Init();
>               CBWindow win = new CBWindow();
>               win.ShowAll();
>               Application.Run();
>           }
>       }
>
>       public class CBWindow : Window
>       {
>           private ListStore store;
>
>           public CBWindow() : base("ComboBox Test")
>           {
>               store = new ListStore(typeof(string));
>               store.AppendValues("A");
>               store.AppendValues("B");
>               store.AppendValues("C");
>               ComboBox cb = new ComboBox(store); // or ComboBox cb = new
> ComboBox(); cb.Model = store;
>
>               cb.WidthRequest = 100;
>               VBox vbox = new VBox();
>               vbox.Add(cb);
>
>               this.Add(vbox);
>           }
>       }
> }
>
> If instead of the code above I use:
>
>               string[] data = {"A", "B", "C"};
>               ComboBox cb = new ComboBox(data);
>
> then the items are displayed, but neither the code in the sample above
> or the following will show the items. In these cases, the values are in
> the Model, they just won't display.
>
>               ComboBox cb = new ComboBox();
>               cb.AppendValues("A");
>               cb.AppendValues("B");
>               cb.AppendValues("C");
>
> I guess I am missing something, but I can't determine what. The only
> example I found on the Internet used the string array for values, and
> this would be difficult to program because in my application there would
> be a variable number of items.
>
> I am using mono 2.6.7 and gtk# 2.12.
>
> Jim
> _______________________________________________
> Gtk-sharp-list maillist  -  Gtk-sharp-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/gtk-sharp-list
>


More information about the Gtk-sharp-list mailing list