C#Combobox 绑定数据库可以输入想要的非数据库内容

来源:互联网 发布:percircle.js 编辑:程序博客网 时间:2024/06/01 09:45
  

using System.Collections;


        /// <summary>
        /// 获取菜品
        /// </summary>
        public void GetFood()
        {
            DataTable dtRole = SqlDBHelper.GetDataTable("SELECT * FROM   餐牌");
            ArrayList roleList = new ArrayList();
            roleList.Add(new DictionaryEntry("0", ""));//输入空格

            foreach (DataRow dr in dtRole.Rows)
            {
                roleList.Add(new DictionaryEntry(dr["DetailFoodId"].ToString(), dr["项目名称"].ToString()));
            }

            ComboxBindSource(this.cmbFoodName, roleList);
        }

        public static void ComboxBindSource(ComboBox cb, ArrayList arList)
        {
            cb.DataSource = arList;
            cb.DisplayMember = "value";
            cb.ValueMember = "key";
        }

 

原创粉丝点击