c# - ComboBox - Set selected item by enum name -
i initialize cb enum values so:
private void initprioritys() { m_prioritycombobox.datasource = enum.getnames(typeof(mpriority)).toarray(); }
after want update selected item:
m_prioritycombobox.selecteditem = (mpriority)i_data.priority;
this enum:
public enum mpriority { critical, high, important, medium }
the problem no matter value i_data.priority has slected item stays first index.
you should change m_prioritycombobox.selecteditem = enum.getname(typeof(mpriority), (mpriority)i_data.priority);
since data source array of strings -- because of enum.getnames(typeof(mpriority)).toarray();
-- not enums, need reference each item string.
Comments
Post a Comment