C#Windows - 如何从ComboBox获取Enum值

use*_*584 4 c#

我将字典绑定到ComboBox,它保存枚举值.检索我使用的选定值

comboBox1.SelectedItem返回维值,说[0,Permanent].我可以检索"永久"并将其转换回枚举.


类似的东西..
Employee.JobType = Enum.Parse(JobType,comboBox1.SelectedItem)

我怎么能实现这个目标?

Luk*_*keH 17

或者:

Employee.JobType = (JobType)Enum.Parse(typeof(JobType), comboBox1.SelectedValue);
Run Code Online (Sandbox Code Playgroud)

要么:

Employee.JobType = (JobType)Enum.Parse(typeof(JobType), comboBox1.SelectedText);
Run Code Online (Sandbox Code Playgroud)

  • 第一个在结尾处需要.ToString()。 (2认同)