ComBoItem.cs 2.75 KB
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GeneralLib
{
    public class ComboItem
    {
        public ComboItem(int indexValue, string displayMember, string enumMember)
        {
            _index = indexValue;
            _Name = displayMember;
            _enumValue = enumMember;
        }

        /// <summary>
        /// 索引ID
        /// </summary>
        private int _index = 0;
        public int Index
        {
            get
            {
                return this._index;
            }
            set
            {
                this._index = value;
            }
        }

        /// <summary>
        /// 显示值
        /// </summary>
        private string _Name = "";
        public string Name
        {
            get
            {
                return this._Name;
            }
            set
            {
                this._Name = value;
            }
        }
        /// <summary>
        /// 枚举值
        /// </summary>
        private string _enumValue = "";
        public string EnumValue
        {
            get { return this._enumValue; }
            set { this._enumValue = value; }
        }






        //        ComboxItem cmitem = new ComboxItem("所有分类","-1");
        //cbxSearchCodeType.Items.Add(cmitem);
        //DataTable dtTypes = CodeTypeDAL.GetTypes();
        //for (int i = 0; i < dtTypes.Rows.Count; i++)
        //{
        //     ComboxItem cmitemfor = new ComboxItem(dtTypes.Rows[i["CodeTypeName"].ToString(),dtTypes.Rows[i]["ID"].ToString());
        //      cbxSearchCodeType.Items.Add(cmitemfor);
        //}
        //cbxSearchCodeType.DisplayMember = "Name";
        //cbxSearchCodeType.ValueMember = "id";
        //cbxSearchCodeType.SelectedIndex = 0;

    }

    public class ComboBoxOper
    {
        public static int GetIndexByValue(System.Windows.Forms.ComboBox cbo, string value)
        {
            try
            {
                int index = 0;
                for (int i = 0; i < cbo.Items.Count; i++)
                {
                    if (((ComboItem)cbo.Items[i]).EnumValue == value)
                    {
                        index = i;
                        break;
                    }
                }
                return index;
            }
            catch
            {
                return 0;
            }
        }

        /// <summary>
        /// 设置ComboBox的值
        /// 杨斌 2014-08-05
        /// </summary>
        /// <param name="cbo"></param>
        /// <param name="text"></param>
        public static void SetComboText(System.Windows.Forms.ComboBox cbo, string text)
        {
            try
            {
                cbo.Text = text;
            }
            catch { }
        }
    }


}