Beispiel #1
0
        /// <summary>
        /// 填充下拉列表
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="list"></param>
        public void _SetListFromDataTable(DataTable dt, string valueCol, string dispCol = null, bool hasBlank = true)
        {
            this.HasBlankItem = hasBlank;
            _Value            = null;
            if (dt != null)
            {
                var list = new List <DataDicModel>();
                if (hasBlank && !list[0].name.IsNullOrEmpty() && !list[0].val.IsNullOrEmpty())
                {
                    var modelB = new DataDicModel();
                    modelB.val  = "";
                    modelB.name = "";
                    list.Insert(0, modelB);
                }

                dispCol = dispCol.IsNullOrEmpty() ? valueCol : dispCol;
                foreach (DataRow row in dt.Rows)
                {
                    var model = new DataDicModel();
                    model.val  = row[valueCol].ToStr();
                    model.name = row[dispCol].ToStr();
                    list.Add(model);
                }

                cmbInput.SelectedValuePath = "val";
                cmbInput.DisplayMemberPath = "name";
                cmbInput.ItemsSource       = list;
                this.List = _GetList <DataDicModel>();
            }
        }
Beispiel #2
0
        /// <summary>
        /// 填充下拉列表
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="list"></param>
        private void SetListFromDataDic(List <DataDicModel> list, bool hasBlank = true)
        {
            _Value = null;
            if (list != null)
            {
                if (hasBlank && list.Count > 0 && !list[0].name.IsNullOrEmpty() && !list[0].val.IsNullOrEmpty())
                {
                    var modelB = new DataDicModel();
                    modelB.val  = "";
                    modelB.name = "";
                    list.Insert(0, modelB);
                }

                cmbInput.SelectedValuePath = "val";
                cmbInput.DisplayMemberPath = "name";
                cmbInput.ItemsSource       = list;
            }
        }