C#中DEV的lookUpEdit控件从数据库中获取下拉框的值

lookUpEdit控件

1.从数据库中取值的代码

 //填充导入表
                DataTable dtDisp = new DataTable();
                dtDisp.Columns.Add("id");
                dtDisp.Columns.Add("name");

                //取值的sql,后边参数统一写成这种形式    "{Main.控件显示名}"
                string sql = string.Format(@"select * from MAPS_SYS_TABLE_PROGRESSBAR where MODULE_ID = '{0}'", ModulesId);
                DataTable dt = BLL_CMS.QueryToTabel(sql);
                if (dt != null && dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        string isVisable = dt.Rows[i]["IS_VISIBLE"].ToString();
                        if ("1".Equals(isVisable))
                        {
                            DataRow dr = dtDisp.NewRow();
                            dr["id"] = dt.Rows[i]["PROGRESSBAR_ID"].ToString();
                            dr["name"] = dt.Rows[i]["PROGRESSBAR_NAME"].ToString();
                            dtDisp.Rows.Add(dr);
                        }
                    }
                }
                lookUpEdit1.Properties.NullText = "请您选择";
                lookUpEdit1.Properties.DataSource = dtDisp;
                lookUpEdit1.Properties.DisplayMember = "name";
                lookUpEdit1.Properties.ValueMember = "id";
                if (lookUpEdit1.Properties.Columns.Count < 1)
                {
                    lookUpEdit1.Properties.Columns.Add(new LookUpColumnInfo("id"));
                    lookUpEdit1.Properties.Columns.Add(new LookUpColumnInfo("name"));
                }
                lookUpEdit1.ItemIndex = -1;
            }

将下拉框内的值直接写死的代码:

       /// 
        /// 填充下拉列表框
        /// 
        private void FillLookUpEdit()
        {
            try
            {
                //填充计算方式
                DataTable dtTableKey = new DataTable();
                dtTableKey.Columns.Add("PROGRESSBAR_ID");
                dtTableKey.Columns.Add("PROGRESSBAR_NAME");

                for (int j = 0; j < 2; j++)
                {
                    DataRow dr = dtTableKey.NewRow();
                    if (j == 0)
                    {
                        dr["PROGRESSBAR_ID"] = "按月销售";
                        dr["PROGRESSBAR_NAME"] = "按月销售";
                        dtTableKey.Rows.Add(dr);

                    }
                    else if (j == 1)
                    {
                        dr["PROGRESSBAR_ID"] = "安全库存";
                        dr["PROGRESSBAR_NAME"] = "安全库存";
                        dtTableKey.Rows.Add(dr);
                    }
                }
                lookUpEdit1.Properties.DataSource = dtTableKey;
                lookUpEdit1.Properties.DisplayMember = "PROGRESSBAR_ID";
                lookUpEdit1.Properties.ValueMember = "PROGRESSBAR_NAME";
                if (lookUpEdit1.Properties.Columns.Count < 1)
                {
                    lookUpEdit1.Properties.Columns.Add(new LookUpColumnInfo("key_name"));
                }
                lookUpEdit1.ItemIndex = 1;
            }


            catch (Exception ex)
            {
                throw ex;
            }
        }

 

你可能感兴趣的:(C#)