Skip to main content

RadioGroupItemCollection.AddEnum(Type) Method

Adds items to the collection that represent elements of the specified enumeration.

Namespace: DevExpress.XtraEditors.Controls

Assembly: DevExpress.XtraEditors.v23.2.dll

NuGet Package: DevExpress.Win.Navigation

Declaration

public void AddEnum(
    Type enumType
)

Parameters

Name Type Description
enumType Type

A System.Type object that is an enumeration whose elements are to be added to the RadioGroup control.

Remarks

This method fetches elements from the specified enumeration and creates new items within the collection that will represent these elements. An item’s value and description are set so as to identify the corresponding element. So, when a specific item is selected in the RadioGroup control, the editor’s edit value will be set to the corresponding enumeration element. You can handle the RadioGroup.SelectedIndexChanged or RepositoryItem.EditValueChanged event to respond to changing the edit value.

Example

This example shows how to display values of a MyColors enum in a RadioGroup control. When the control’s item is selected, the corresponding color is applied to the radio group.

RadioGroup-AddEnum

using DevExpress.XtraEditors;

enum MyColors { Bisque, Coral, SeaShell, Crimson }

private void Form1_Load(object sender, EventArgs e) {
    radioGroup1.Properties.Items.AddEnum(typeof(MyColors));
    radioGroup1.Properties.EditValueChanged += radioGroup1_EditValueChanged;
    radioGroup1.SelectedIndex = 2;
    radioGroup1.Properties.Columns = 2;
}

void radioGroup1_EditValueChanged(object sender, EventArgs e) {
    RadioGroup rg = sender as RadioGroup; 
    if(rg != null) {
        MyColors selectedColor = (MyColors) rg.EditValue;
        (sender as Control).BackColor = Color.FromName(selectedColor.ToString());
    }
}
See Also