[Gtk-sharp-list] Add data to ComboBox

Ryan rthomp@sympatico.ca
Tue, 23 Nov 2004 22:58:59 -0500


Dan Winship wrote:

>On Mon, 2004-11-22 at 06:54 -0500, Ryan wrote:
>  
>
>>Just a few questions on Gtk.ComboBox in gtk-sharp 1.9.0.
>>
>>How do you add data to it?
>>    
>>
>
>You need to create a TreeModel and either create the ComboBox with the
>TreeModel constructor, or set its Model property after creating it. Then
>you add things to the TreeModel, and they show up in the ComboBox. Note
>that I'm pretty sure that using TreeModel is currently really annoying,
>but Mike is working on that (but he's on vacation this week, so don't
>expect any progress until next week).
>
>  
>
>>And lastly - does it support being populated by an ArrayList?
>>    
>>
>
>Not in the current system. Possibly eventually.
>
>-- Dan
>
>
>
>  
>
I managed to get a little bit further thanks to your reply. The rows are 
being added but the strings are missing. Below is similar code to what I 
have minus other junk that's being done.  I think all the pertinent 
stuff is there.  Am I missing something?

           typesSelect = new ComboBox(model);
           TreeStore typesStore = new TreeStore(typeof(string));
           string [] types = userAccount.GetTypes();
           typesSelect.Model = typesStore;                    
            for(int i = 0; i < types.Length; i++)
           {
               Console.WriteLine(types[i]);
               TreeIter iter = typesStore.AppendValues(types[i]);
           }

Thanks for the help. I've been at this for two days off and on and it's 
driving me nuts.

RT