实现一个combobox,将其各个下拉项与枚举进行绑定
效果图如下:
代码详解如下:
枚举:
public enum StoreSite { /// <summary> /// 未知 /// </summary> [EnumTitle("未知")] None = 0, /// <summary> /// 北京 /// </summary> [EnumTitle("北京")] Beijing = 1, /// <summary> /// 上海 /// </summary> [EnumTitle("上海")] Shanghai = 2, /// <summary> /// 深圳 /// </summary> [EnumTitle("深圳")] Shenzhen = 3, /// <summary> /// 香港 /// </summary> [EnumTitle("香港")] Hongkong = 4 }
客户端
namespace ProductManage { public partial class AddDataFrame : Form { public AddDataFrame() { InitializeComponent(); #region 数据的初始化 foreach (string s in Enum.GetNames(typeof(StoreSite))) { if (s!="None") { this.comb_storesite.Items.Add(s); } } #endregion }
}
}