Search code examples
c#winformscomboboxtoolbarinfragistics

How to populate ComboBoxTool.ValueList with enum values?


I am working on toolbar and I want to display enum with ComboBoxTool at a toolbar. The ComboBoxTool takes ValueList object. Enum needs to convert ValueList type. How can I add enum to ValueList? Thank for answers. enter image description here


Solution

  • Loading the specified combo box with the members of the specified enumeration:

    public void LoadEnumsIntoCombo(ComboBoxTool combo, Type type)
    {
        Array enumValues = Enum.GetValues(type);
        Infragistics.Win.ValueList valueList = new Infragistics.Win.ValueList();
        foreach(object value in enumValues)
        {                
            valueList.ValueListItems.Add(new ValueListItem(value, value.ToString()));
        }
        combo.ValueList = valueList;
    }
    

    And example of calling this method:

    var comboBoxTool1 = new Infragistics.Win.UltraWinToolbars.ComboBoxTool("ComboBoxTool1");
    LoadEnumsIntoCombo(comboBoxTool1, typeof(ToolbarStyle));