【问题标题】:Data binding between enum to ComboBox枚举到 ComboBox 之间的数据绑定
【发布时间】:2013-12-07 08:19:51
【问题描述】:
Public Class Person
{
 private enum accountType
 {
   Savings,
   Cheking
 },

}

在 Windows 窗体中,我有一个组合框帐户类型。 如何将 Person 类中的数据绑定到 Windows 表单组合框。当我运行表单组合框将自动显示枚举列表。我该如何解决。任何人帮助我。 一部分枚举 accountType 将是公开的。我是 C# 新手。

【问题讨论】:

    标签: c#


    【解决方案1】:

    嘿嘿,希望对你有帮助

          public enum AccountType
          {
             Savings,
             Cheking
          }
    

    在您的 Form1.cs 文件中编写以下代码 我假设您的表单名称是 Form1

        public Form1 ()
        {
            InitializeComponent();
            BindComboList();
        }
    
        private void BindComboList()
        {
            var values = Enum.GetValues(typeof(AccountType));
            foreach (var item in values)
            {
                cmbAccountType.Items.Add(item);
            }
        }
    

    你已经完成了。

    【讨论】:

      【解决方案2】:

      试试这个;

      cbaccountType.DataSource=Enum.GetValues(typeof(accountType));
      

      cbaccountType 是你的 ComboBox。

      【讨论】:

        猜你喜欢
        • 2011-07-03
        • 1970-01-01
        • 2011-02-06
        • 1970-01-01
        • 2016-03-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多