zoukankan      html  css  js  c++  java
  • ComBox绑定枚举

    (转自:http://blog.csdn.net/chao88552828/article/details/9903159)

     /// <summary>
            /// 参数枚举
            /// </summary>
            public enum ParematerType
            {
                //酒店
                酒店 = 8,
                //景区等级
                景区 = 4,
                //餐馆/农家乐 等级
                餐馆 = 9,
                //购物
                购物 = 7,
                //娱乐
                娱乐 = 5,
            }
            /// <summary>
            /// 窗体加载参数类型
            /// </summary>
            private void initializeComBox()
            {
                Type parematerType = typeof(SystemEnum.ParematerType); 
                foreach (int index in Enum.GetValues(parematerType))
                {
                    string name = Enum.GetName(parematerType, index);//ex:餐馆 
                    string value = index.ToString();//ex:9
                    //需要增加引用:System.Web
                    //引用命名空间:using System.Web.UI.WebControls;
                    //ListBox 也可用这个方法
                    ListItem item = new ListItem();
                    item.Text = name;
                    item.Value = value;
                    cmbParematerType.Items.Add(item);
                }
            }
            ///获取下拉框的选中内容
            private void getSelectComBox()
            {
                ListItem item =(ListItem)(cmbParematerType.SelectedItem);
                string name = item.Text;
                string value = item.Value;
            }
            ///获取ListBox的选中内容
            private void getSelectsListBox()
            {
                //lbShow是ListBox的名称
                for (int i = 0; i < lbShow.SelectedIndices.Count; i++)
                    {
                        int index = this.lbShow.SelectedIndices[i];
                        string value= ((ListItem)(lbShow.Items[index])).Value;
                        string name = ((ListItem)(lbShow.Items[index])).Text;
                    }
            }

    ----------------------------------------------------------------
    ps:模板化
    private void initializeComBox<T>(ComboBox combox)
    {
    var itemType = typeof(T);
    foreach (int index in Enum.GetValues(itemType))
    {
    var item = new DictionaryEntry();
    item.Key = Enum.GetName(itemType, index);
    item.Value = index.ToString();
    combox.Items.Add(item);
    }
    combox.DisplayMember = "Key";
    combox.ValueMember = "Value";
    }
     
  • 相关阅读:
    css如何去掉select原始样式
    Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL
    eclispe+maven+ssm+sql_server/mysql配置
    解决Missing artifact com.microsoft.sqlserver:sqljdbc4:jar:4.0问题
    eclipse alt+/智能提示错误问题
    去除input边框 input去除边框 去除input获取焦点时的蓝色外边框
    java对sql server的增删改查
    java连接sql server 2008
    卸载sql server 2008
    FTP的vsftpd.conf含义
  • 原文地址:https://www.cnblogs.com/FindSelf/p/4021901.html
Copyright © 2011-2022 走看看