-2

How to provide the enum values on to checked combobox edit control in dev express?

public enum AccessRoles
{
    User,
    Administrator
}

foreach (var item in Enum.GetValues(typeof(AccessRoles)))
{
    checkedComboBoxEdit1.Properties.Items.AddRange(Enum.GetValues(typeof(item)));
}

How do I bind the enum value on to checkedcomboBoxedit?

gunr2171
  • 16,104
  • 25
  • 61
  • 88
Myself
  • 1
  • 3
  • 2
    we need way more detail then. this. Please show some code – psoshmo Jul 15 '15 at 12:42
  • checkedComboBoxEdit1.Properties.Items.AddRange(Enum.GetValues(typeof(AccessRoles))); – Myself Jul 15 '15 at 12:47
  • possible duplicate of [How do you bind an Enum to a DropDownList control in ASP.NET?](http://stackoverflow.com/questions/61953/how-do-you-bind-an-enum-to-a-dropdownlist-control-in-asp-net) – Bsa0 Jul 15 '15 at 12:49
  • public enum AccessRoles { User, Administrator } foreach (var item in Enum.GetValues(typeof(AccessRoles))) { checkedComboBoxEdit1.Properties.Items.AddRange(Enum.GetValues(typeof(item))); } how do i bind the values of enum on to checked combo box edit in the above code? @gunr2171 – Myself Jul 15 '15 at 13:03

4 Answers4

0

try something like this. Bind your comboboxedit to your list (or whatever) of enums.

then in your comboboxedit

<dxe:ComboBoxEdit //stuff here>
     <dxmvvm:Interaction.Behaviors>
            <dxmvvm:EnumItemsSourceBehavior EnumType="{x:Type local:AccessRoles}" SortMode="DisplayName"/>
        </dxmvvm:Interaction.Behaviors>
        <dxe:ComboBoxEdit.ItemTemplate>
</dxe:ComboBoxEdit>

let me know if this works, Ive never personally tried it before. Its new to version 14.2, so if you have an older version let me know

psoshmo
  • 1,490
  • 10
  • 19
0

This piece of code worked for binding those Enum values on to CheckedComboEdit.

checkedComboBoxEdit1.Properties.DataSource = Enum.GetValues(typeof(AccessRoles));

Myself
  • 1
  • 3
0

I think the best Way To Use Enum with DevExpress is DevExpress.XtraEditors.ImageComboBoxEdit or Repository (RepositoryItemImageComboBox)

        Type EnumType=typeof(MyEnum);
        DevExpress.XtraEditors.ImageComboBoxEdit ED = new 
        DevExpress.XtraEditors.ImageComboBoxEdit();
        ED.Properties.AddEnum(EnumType);
        //or Manualy to get Description From Resource or any way
        foreach (var item in Enum.GetValues(EnumType))
        {
            ImageComboBoxItem I = new ImageComboBoxItem();
            I.Value = item;
            I.Description = 
            GetEnumDescFunctionOrResourceValue(item);
            ED.Properties.Items.Add(I);
        }
0

You can also use "Flags" attribute and "SetFlag" method.

[Flags]
public enum FruitTypes
{
   None,
   Apple,
   Banana,
   Graphes,
   Mango
}


...
var editor = new CheckedComboBoxEdit();
// set flags
editor.SetFlags(typeof(FruitTypes));
...
eloiz
  • 81
  • 9