How to add a combo box with runtime generated items to a Dialog object.
Combo boxes in Dialogs are added by adding a DialogField object with the type of an enum. The enum is then controlling what items you can pick from the combo box.
But sometimes you may need to add a combo box with run time generated item and you of course don't have an enum for those. The Dialog framework won't really allow you to do that - it insists on getting the type of an enum.
Usually I solve this by creating a form to use as dialog in stead, but yesterday it occured to me that I could add a combo box the way Dialog likes it and then 'hijack' the form control object and modify it to my needs.
So I add a DialogField with the type of any enum, except NoYes, which makes Dialog create the combo box control and then I get hold of the control and modify its properties. The NoYes enum won't work becasue it'll make Dialog add a check box and not a combo box.
Here's an example:
static void comboBoxHiJacker(Args _args)
{
Dialog dialog = new Dialog();
DialogField dialogField;
FormBuildComboBoxControl formComboBoxControl;
;
// Any enum, except NoYes, will do.
dialogField = dialog.addField(typeId(ABC));
formComboBoxControl = dialogField.control();
formComboBoxControl.enumType(0);
formComboBoxControl.label("My combo box");
formComboBoxControl.items(3);
formComboBoxControl.item(1);
formComboBoxControl.text("Item 1");
formComboBoxControl.item(2);
formComboBoxControl.text("Item 2");
formComboBoxControl.item(3);
formComboBoxControl.text("Item 3");
dialog.run();
info(dialogField.value());
}
This posting is provided "AS IS" with no warranties, and confers no rights.
Comments
Anonymous
October 04, 2007
Imagine a combobox based on an enum. By default it contains a list of items that correspond to the valuesAnonymous
January 18, 2009
PingBack from http://www.keyongtech.com/319461-how-to-filter-the-enum