All docs
V20.2
20.2
20.1
19.2
19.1
The page you are viewing does not exist in version 19.1. This link will take you to the root page.
18.2
The page you are viewing does not exist in version 18.2. This link will take you to the root page.
18.1
The page you are viewing does not exist in version 18.1. This link will take you to the root page.
17.2
The page you are viewing does not exist in version 17.2. This link will take you to the root page.

BaseListBoxControl.AddEnum<TEnum>(Converter<TEnum, String>, Boolean) Method

Adds new items that represent elements of the specified enumeration to the control. Allows you to customize item descriptions and specify whether underlying integer values are assigned to the item values.

Namespace: DevExpress.XtraEditors

Assembly: DevExpress.XtraEditors.v20.2.dll

Declaration

public void AddEnum<TEnum>(
    Converter<TEnum, string> displayTextConverter,
    bool addEnumeratorIntegerValues
)
Public Sub AddEnum(Of TEnum)(
    displayTextConverter As Converter(Of TEnum, String),
    addEnumeratorIntegerValues As Boolean
)

Parameters

Name Type Description
displayTextConverter Converter<TEnum, String>

A System.Converter delegate that generates item descriptions to be displayed.

addEnumeratorIntegerValues Boolean

true, if values for generated items should store numeric enumerator values; false, if these values should store constant enumerator names instead.

Type Parameters

Name Description
TEnum

The type of the required enumeration.

Remarks

This method creates ListBoxItem objects from the specified enumeration's members and uses the objects to populate a BaseListBoxControl's descendant. The new items are stored in the BaseCheckedListBoxControl.Items and BaseImageListBoxControl.Items collection.

The BaseListBoxControl's descendant controls provide additional settings:

  • The Value property (see ListBoxItem.Value) stores an item's constant name or integer value. This depends on the value the addEnumeratorIntegerValues parameter receives.
  • The Description property (see CheckedListBoxItem.Description and ImageListBoxItem.Description) stores an item's description displayed to the end user. You can generate the description in a delegate and pass it to the displayTextConverter parameter.

Examples

The following code example shows how to populate the ImageListBoxControl, a BaseListBoxControl descendant, with items from the specified enum.

BaseListBoxControlImageListBoxControlAddEnum

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 ImageListBoxControl with items
            // generated based on the Day enumeration constants.
            // The method parameter specifies the delegate 
            // that encapsulates the method providing
            // custom item descriptions.
            // The second parameter set to true specifies
            // item values to be set to enumeration constant
            // integer values instead of constant names.
            imageListBoxControl1.AddEnum<Day>(new Converter<Day, string>(MyConverter), true);
        }

        // 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();
        }
    } 
}
See Also