In many code samples, the items in a ComboBox are built before the ComboBox, and passed in the constructor. However, when using XRC, or when you want to populate the ComboBox dynamically, this method cannot be used. You can do this by using the methods from ItemContainer, from which ComboBox inherits. First, have a look at the documentation :

   1 import wx
   2 help(wx.ItemContainer)

The main methods are Append, Delete, Clear and GetSelection, which do what you expect.

There is a rather useful feature in ComboBox, which is that each (string) item can be associated to a client object by the component (either by giving it in Append or SetClientData), so that you can get it later on by GetClientData. This can save you the hassle of maintaining an external list or hashtable, which is a good thing or bad thing depending on whether you're writing a quick hack or a proper MVC application :).

ManipulatingComboBoxItems (last edited 2008-03-11 10:50:25 by localhost)

NOTE: To edit pages in this wiki you must be a member of the TrustedEditorsGroup.