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

Jim Orcheson jim at va3hj.ca
Tue Jun 14 09:58:33 EDT 2011


Krzysztof's answer to a different post (http://lists.ximian.com/pipermail/gtk-sharp-list/2011-June/010734.html) led me to the solution. To ensure consistent display of the data in a ComboBox, I need to add a CellRenderer. So, the code should look like this:

		public CBWindow() : base("ComboBox Test")
		{
			store = new ListStore(typeof(string));
			
			ComboBox cb = new ComboBox();
			cb.WidthRequest = 100;
			CellRendererText ct = new CellRendererText();
			cb.PackStart(ct, false);
			cb.AddAttribute(ct, "text", 0);
			cb.Model = store;
			store.AppendValues("A");
			store.AppendValues("B");
			store.AppendValues("C");
			VBox vbox = new VBox();
			vbox.Add(cb);
			
			this.Add(vbox);
		}
			


rather than:

>>            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);
>>            }
>


More information about the Gtk-sharp-list mailing list