如何在组合框中显示枚举值?
如何在组合框中显示枚举值?下面的代码导致组合框的所有显示名称均为“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;
How do i show enum values in a combo-box? The code below result in the combobox having all displayed names being "caseHandler.cState". I wanted it to have the actual names of the enum values.
My enum is defined as follows:
public enum caseState
{
Active = 1,
Finished,
Problem
}
I have a class that is defined as this:
public class cState
{
public string _name;
public int _id;
public cState(int id,string name)
{
_name = name;
_id = id;
}
}
And the code for populating my combobox:
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;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否尝试过使用
And 在检索数据时只是解析它
Have you tried to use
And when retrieving data just Parse it
在这里我的代码,您可以将文本和值放在一起并填充组合框
Here My Code , you can have text and value together and fill Combobox