comboBox1.DataSource = GetDataTable();
comboBox1.DisplayMember = "Name";
comboBox1.ValueMember = "Value";
public static DataTable GetDataTable()
{
Type t = typeof(BookingStatus); //创建类型
FieldInfo[] fieldinfo = t.GetFields(); //获取字段信息对象集合
DataTable table = new DataTable();
table.Columns.Add("Name", typeof(String));
table.Columns.Add("Value", typeof(Int32));
foreach (FieldInfo field in fieldinfo)
{
if (!field.IsSpecialName)
{
DataRow row = table.NewRow();
row[0] = field.Name; //获取文本字段
row[1] = (int)field.GetRawConstantValue(); //获取int数值
table.Rows.Add(row);
}
}
return table;
}
public enum BookingStatus
{
未提交 = 1,
已提交,
已取消,
已定妥 = 6
}