码迷,mamicode.com
首页 > 其他好文 > 详细

ComBox绑定枚举

时间:2014-10-13 13:00:59      阅读:153      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   os   ar   for   sp   div   

(转自: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;
                }
        }

 

ComBox绑定枚举

标签:style   blog   http   color   os   ar   for   sp   div   

原文地址:http://www.cnblogs.com/FindSelf/p/4021901.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!