[Gtk-sharp-list] ComboBox Items Don't Display
Jim Orcheson
jim at va3hj.ca
Mon Jun 13 09:15:46 EDT 2011
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
More information about the Gtk-sharp-list
mailing list