【发布时间】:2011-07-01 05:02:51
【问题描述】:
如何在组合框中显示枚举值?下面的代码导致组合框的所有显示名称都是“caseHandler.cState”。我希望它具有枚举值的实际名称。
我的枚举定义如下:
public enum caseState
{
Active = 1,
Finished,
Problem
}
我有一个这样定义的类:
public class cState
{
public string _name;
public int _id;
public cState(int id,string name)
{
_name = name;
_id = id;
}
}
以及用于填充我的组合框的代码:
ArrayList AL = new ArrayList();
foreach (string cs in Enum.GetNames(typeof(caseState)))
{
cState aEnum = new cState((int)Enum.Parse(typeof(caseState),cs),cs);
AL.Add(aEnum);
}
cbState.DisplayMember = "_name";
cbState.ValueMember = "_id";
cbState.DataSource = AL;
【问题讨论】:
标签: c# winforms enums combobox