RepositoryItemImageComboBox.AddEnum<TEnum>(Converter<TEnum, String>) Method
Populates this RepositoryItemImageComboBox with items generated from values of the specific enumeration and replaces default item descriptions.
Namespace: DevExpress.XtraEditors.Repository
Assembly: DevExpress.XtraEditors.v24.2.dll
Declaration
Parameters
Name | Type | Description |
---|---|---|
displayTextConverter | Converter<TEnum, String> | A Delegate that encapsulates a method which replaces generated items’ captions. |
Type Parameters
Name |
---|
TEnum |
Remarks
Many DevExpress editors and control provide the capability to fetch enumeration values and generate items using these values. To do this, use the required AddEnum/AddEnum<T> method overload. These overloads provide various parameters.
addEnumeratorIntegerValues
Typically, an editor item has the Value and Description properties. An item value is passed to the editor’s BaseEdit.EditValue property, while an item description is shown to end-users on screen. By default, when you populate an editor from an enumeration, these two values are the same. If the addEnumeratorIntegerValues parameter is set to true, item values will store numeric constants related to enumeration values, not their constant names.
displayTextConverter
This parameter allows you to specify a delegate that encapsulates a method which modifies item descriptions. Note that you can do the same thing by declaring Description attributes before enumeration values as shown below.
skipComposite
When set to true, this parameter prevents the editor from generating items that correspond to enumeration values with composite bit-flags. Refer to the Non-exclusive members and the Flags attribute article section to learn more.
skipNone
This parameter allows you to skip enumeration values that do not have manually assigned numeric values.
The figure below illustrates various DevExpress editors populated from a sample enumeration.
Example
The following example shows how to populate the CheckedListBoxControl and ImageListBoxControl with items using the BaseListBoxControl.AddEnum and BaseListBoxControl.AddEnum<TEnum> methods.
The image below shows the result of executing the code in the example. It is assumed that the controls are dropped on the form at design time.
using System;
using System.ComponentModel;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public enum Day {
// The Description attribute can be used
// to provide descriptions for items.
[Description("Saturday")]
Sat = 7,
Sun = 1,
Mon,
Tue,
Wed,
Thu,
Fri
};
public partial class Form1 : DevExpress.XtraEditors.XtraForm {
public Form1() {
InitializeComponent();
// Populates the CheckedListBoxControl with items
// generated based on the Day enumeration constants.
// The second parameter set to true specifies
// item values to be set to enumeration constant
// integer values instead of constant names.
checkedListBoxControl1.AddEnum(typeof(Day), true);
// Populates the ImageListBoxControl with items
// generated based on the Day enumeration constants.
// The method parameter specifies the delegate
// that encapsulates the method providing
// custom item descriptions.
imageListBoxControl1.AddEnum<Day>(new Converter<Day,string>(MyConverter));
}
// Returns a custom string based on the specified day.
public static string MyConverter(Day d) {
Type dayType = d.GetType();
Type dayUnderlyingType = Enum.GetUnderlyingType(dayType);
return Convert.ChangeType(d, dayUnderlyingType).ToString() + ". " + d.ToString();
}
}
}