Modellen
The model for a DropDown can be defined and filled exactly as for a ListView or a ColumnView. It must be a subclass of Glib::Object. For instance, you might have a DropDown with one integer and one text column, like so:
class ModelColumns : public Glib::Object
{
public:
int m_col_id;
Glib::ustring m_col_name;
static Glib::RefPtr<ModelColumns> create(
int col_id, const Glib::ustring& col_name)
{
return Glib::make_refptr_for_instance<ModelColumns>(
new ModelColumns(col_id, col_name));
}
protected:
ModelColumns(int col_id, const Glib::ustring& col_name)
: m_col_id(col_id), m_col_name(col_name)
{}
};
Glib::RefPtr<Gio::ListStore<ModelColumns>> m_ListStore;
After appending rows to this model, you should provide the model to the DropDown with the set_model() method. Unless you use the StringList model, you also need to set a ListItemFactory with set_factory(). If you want the items in the dropdown menu to look different from the item in the DropDown widget, you also need to set a separate ListItemFactory with set_list_factory().