I'm trying to populate the datasource from my combobox with following code:
Here is the part where I create my binding
_columnsLayoutBinding.DataSource = _myColumnsLayout;
ColumnsLayoutDataGrid.DataSource = _columnsLayoutBinding;
DataGridCreator.CurrentInstance.CreateDataGrid<ConfigColumns>(ref ColumnsLayoutDataGrid);
Then inside the DataGridCreator method call, I do some checking and populate the combobox with the values
var list = (from object type in System.Enum.GetValues(typeof (FontSizeType)) select new KeyValuePair<string, int>(type.ToString(), (int)type)).ToList();
comboBox.DataSource = list;
comboBox.DisplayMember = "Key";
comboBox.ValueMember = "Value";
return comboBox;
The problem is: When is when a replace the code where I populate the datasource with this:
var list = new List<KeyValuePair<string, int>>();
var id = 0;
foreach (var type in System.Enum.GetValues(typeof(FontSizeType)))
{
list.Add(new KeyValuePair<string, int>(type.ToString(), id));
id++;
}
comboBox.DataSource = list;
comboBox.DisplayMember = "Key";
comboBox.ValueMember = "Value";
return comboBox;
It works. The problem seems the value member initial value 0. Then it starts with 0 - ok. When it starts with the enum starting int(6) - Not working.
Here is my enumerator:
[DataContract]
[Serializable]
[Flags]
public enum FontSizeType
{
[EnumMember]
Seis = 6,
[EnumMember]
Sete = 7,
[EnumMember]
Oito = 8,
[EnumMember]
Nove = 9,
[EnumMember]
Dez = 10,
[EnumMember]
Onze = 11
In your first example you are populating the KeyValuePair.Values with the integer value of each corresponding Enum. While in the second part you are using a counter starting at zero. Try the below:
Additionally in the first example you are using the FontSizeType Enum and in the 2nd you are using FontStyle. Is that intentional? Not enough context to tell for sure.