jmaeding
Joined: 11 Apr 2008 Posts: 67
|
Posted: Tue Mar 01, 2011 1:14 am Post subject: Look up enum val from combobox editor key/val list |
|
|
I have a combobox editor assigned in getcelldata, and am setting its datasource to a key-value list of enums and their descriptions using a helper function called EnumToIList:
comboBox.DataSource = typeof HAHelper.clsImageModStatus).EnumToIList();
comboBox.DisplayMember = "Value";
comboBox.ValueMember = "Key";
since i am doing this programatically, I am using SetValueForCell like this:
Code: | protected override bool SetValueForCell(Row row, Column column, object oldValue, object newValue) {
// use the row binding to set the value
//
RowBinding binding = this.GetBindingForRow(row);
if (column == vtColStatus) {
string strVal = (string)newValue;
List<string> descs = typeof(HAHelper.clsImageModStatus).EnumToDescList();
int index = 0;
foreach (string desc in descs) {
if (desc == strVal) {
return binding.SetCellValue(row, column, oldValue, (HAHelper.clsImageModStatus)index);
}
index++;
}
return false;
}
else{
return binding.SetCellValue(row, column, oldValue, newValue);
}
} |
This is junky, to look up an enum val by looping through its list of descriptions. The right way is to get the value from the combobox datasource, using the newvalue as key.
How can i access the key-val list? I am wondering if its safe to do, since editor controls are cached and all.
thx _________________ James M |
|