Hi,
I have this enum type:
public enum SchedActiveEnum
{
[Description("All")]
All,
[Description("Y")]
Y,
[Description("N")]
N
}
What is the better way for bind it in a combobox?
I would like to display the description but get the value.
I would like to display the description but get the value.
Thanks.

VulpesPosted Feb 23, 2015, 8:21 AM
Instead, I either paste in code which has already been formatted directly from Visual Studio or prepare the formatted code initially in Notepad and then paste it in from there.
Roberto SalemiPosted Feb 23, 2015, 4:13 AM
private Dictionary
public Dictionary
{
get
{
if (_schedActive == null)
{
_schedActive = new Dictionary
//Permette di visualizzare la Description dell'Enum
var myList = Enum.GetValues(typeof(Definition.SchedActiveEnum)).Cast
{
value,
(Attribute.GetCustomAttribute(
value.GetType().GetField(value.ToString()),
typeof(DescriptionAttribute)) as DescriptionAttribute).Description
}
);
foreach (var item in myList)
{
_schedActive.Add((Definition.SchedActiveEnum)item.value, item.Description);
}
}
return _schedActive;
}
}
in xaml:
ItemsSource="{Binding SchedActive}"
DisplayMemberPath="Value"
SelectedValuePath="Key"
Width="50">
Thanks.
OT. How can I format my code in this forum?
VulpesPosted Feb 20, 2015, 11:53 AM
though I thought you said you wanted to display the Descriptions in your opening post?
Roberto SalemiPosted Feb 20, 2015, 10:47 AM
VulpesPosted Feb 19, 2015, 12:41 PM
http://codereview.stackexchange.com/questions/39163/loading-a-combobox-with-an-enum-and-binding-to-it
In your case, this code should work for WPF: