Beispiel #1
0
        /// <summary>
        /// 绑定LookUpEdit
        /// </summary>
        /// <param name="dt">数据集合</param>
        /// <param name="lst">LookUpEdit控件</param>
        /// <param name="needQingXuanZ">是否需要请选择</param>
        public static void BindDropDownList(DataTable dt, LookUpEdit lst, bool needQingXuanZ, int dropDownRows)
        {
            if (dt.Columns.Count > 2)
            {
                return;
            }

            if (dt.Columns.Count == 1)
            {
                dt = ConvertHelper.AddColumn(dt);
            }

            if (needQingXuanZ)
            {
                DataRow dr = dt.NewRow();
                dr[0] = "--请选择--";
                dr[1] = "-99999";
                dt.Rows.InsertAt(dr, 0);
            }

            lst.Properties.DataSource    = dt;
            lst.Properties.DisplayMember = dt.Columns[0].ColumnName;
            lst.Properties.ValueMember   = dt.Columns[1].ColumnName;
            lst.Properties.Columns.Clear();
            lst.Properties.Columns.Add(new LookUpColumnInfo(dt.Columns[0].ColumnName, 80));
            lst.Properties.ShowHeader       = false;
            lst.Properties.ShowFooter       = false;
            lst.Properties.NullText         = "";
            lst.Properties.PopupFormMinSize = new System.Drawing.Size(10, 10);
            lst.Properties.BestFitMode      = BestFitMode.BestFitResizePopup; //下拉框在第二个Tab页时,BestFit()不能显示全部
            lst.Properties.PopupWidth       = lst.Properties.BestFit();       //BestFitMode只在第一次弹出下拉框时生效,特殊情况不能满足
            lst.Properties.DropDownRows     = dropDownRows;

            if (dt.Rows.Count > 0)
            {
                lst.Properties.ForceInitialize();
                lst.ItemIndex = 0;
            }
        }