This question is locked. New answers and comments are not allowed.
Hi,
I've got a combobox that I will fill with the items set in an enumeration. To do this I'm using a helper:
Copying and pasting the example in the page: Missing Enum.GetValues() when doing Silverlight for instance ?
The combo box items appear correctly with the value of the enumerator, but when I select one of its values, instead of the value, I get the index or key :(
I tried to create a SelectionBoxItemTemplate but when I try to bind it I don't get any value, what am I doing wrong?
Thanks to all,
L. Pinho
I've got a combobox that I will fill with the items set in an enumeration. To do this I'm using a helper:
Copying and pasting the example in the page: Missing Enum.GetValues() when doing Silverlight for instance ?
| using System; using System.Linq; using System.Collections.Generic; using System.Reflection; /// <summary> |
| /// Helper class to allow users to get the values of a enumeration |
| /// </summary> |
| public static class EnumHelper |
| { |
| /// <summary> |
| /// Get values of an enumeration of type T |
| /// </summary> |
| /// <typeparam name="T">Enumeration type</typeparam> |
| /// <returns>List of types in a enumeration</returns> |
| public static T[] GetValues<T>() |
| { |
| Type enumType = typeof(T); |
| if (!enumType.IsEnum) |
| { |
| throw new ArgumentException("Type '" + enumType.Name + "' is not an enum"); |
| } |
| List<T> values = new List<T>(); |
| var fields = from field in enumType.GetFields() |
| where field.IsLiteral |
| select field; |
| foreach (FieldInfo field in fields) |
| { |
| object value = field.GetValue(enumType); |
| values.Add((T)value); |
| } |
| return values.ToArray(); |
| } |
| /// <summary> |
| /// Get all the values of an enumeration of Type enumType |
| /// </summary> |
| /// <param name="enumType">Enumeration type</param> |
| /// <returns>Array of objects</returns> |
| public static object[] GetValues(Type enumType) |
| { |
| if (!enumType.IsEnum) |
| { |
| throw new ArgumentException("Type '" + enumType.Name + "' is not an enum"); |
| } |
| List<object> values = new List<object>(); |
| var fields = from field in enumType.GetFields() |
| where field.IsLiteral |
| select field; |
| foreach (FieldInfo field in fields) |
| { |
| object value = field.GetValue(enumType); |
| values.Add(value); |
| } |
| return values.ToArray(); |
| } |
| } |
The combo box items appear correctly with the value of the enumerator, but when I select one of its values, instead of the value, I get the index or key :(
I tried to create a SelectionBoxItemTemplate but when I try to bind it I don't get any value, what am I doing wrong?
| <telerikInput:RadComboBox.SelectionBoxItemTemplate> |
| <DataTemplate> |
| <TextBlock Text="{Binding Path=Value}"/> |
| </DataTemplate> |
| </telerikInput:RadComboBox.SelectionBoxItemTemplate> |
Thanks to all,
L. Pinho