コード例 #1
1
ファイル: uc_gridcontrol.cs プロジェクト: s7loves/mypowerscgl
        public void InitCol(string[] arrCol, LP_Temple lp) {
            m_ColName = arrCol;
            DataTable ds = new DataTable();
            string[] arrColtype = lp.ComBoxItem.Split('|');
            for (int i = 0; i < arrCol.Length; i++) {
                if (arrCol[i].ToString() == "") continue;
                if (arrColtype[i].IndexOf("RepositoryItemCalcEdit") > -1 || arrColtype[i].IndexOf("RepositoryItemSpinEdit") > -1) {
                    ds.Columns.Add(arrCol[i], typeof(double));
                } else
                    if (arrColtype[i].IndexOf("RepositoryItemDateEdit") > -1) {
                        ds.Columns.Add(arrCol[i], typeof(DateTime));
                    } else {
                        ds.Columns.Add(arrCol[i], typeof(string));
                    }
                ds.Columns[i].Caption = arrCol[i];
            }
            try {
                gridControl1.DataSource = ds;
            } catch (Exception err) {

            }
            DevExpress.XtraGrid.Views.Grid.GridView grid = gridView1;
            grid.OptionsBehavior.AllowAddRows = DevExpress.Utils.DefaultBoolean.True;
            grid.OptionsBehavior.AllowDeleteRows = DevExpress.Utils.DefaultBoolean.True;
            grid.OptionsView.NewItemRowPosition = DevExpress.XtraGrid.Views.Grid.NewItemRowPosition.Bottom;
            grid.OptionsView.ShowGroupPanel = false;
            string[] comItem = SelectorHelper.ToDBC(lp.ComBoxItem).Split('|');
            ((System.ComponentModel.ISupportInitialize)(this.gridControl1)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.gridView1)).BeginInit();
            for (int i = 0; i < grid.Columns.Count; i++) {

                if (grid.Columns[i].FieldName == "序号" || grid.Columns[i].FieldName == "月份" || grid.Columns[i].FieldName == "季度") {
                    grid.Columns[i].MinWidth = 20;
                }
                Regex r1 = new Regex(@"(?<=" + i + ":).*?(?=])");
                string strcom = r1.Match(comItem[i]).Value;

                if (strcom.IndexOf("RepositoryItemDateEdit") > -1) {
                    r1 = new Regex(@"(?<=:).*");
                    DevExpress.XtraEditors.Repository.RepositoryItemDateEdit date =
                             new DevExpress.XtraEditors.Repository.RepositoryItemDateEdit();
                    if (r1.Match(strcom).Value != "") {
                        date.Properties.EditMask = r1.Match(strcom).Value;
                        date.Mask.UseMaskAsDisplayFormat = true;
                        if (r1.Match(strcom).Value.ToLower().IndexOf("hh") > -1) {
                            date.VistaDisplayMode = DevExpress.Utils.DefaultBoolean.True;
                            date.VistaEditTime = DevExpress.Utils.DefaultBoolean.True;
                        }
                    }
                    grid.Columns[i].ColumnEdit = date;
                    grid.Columns[i].DisplayFormat.FormatString = date.Properties.EditMask;
                    grid.Columns[i].ColumnEdit.EditFormat.FormatString = date.Properties.EditMask;
                } else if (strcom.IndexOf("RepositoryItemCalcEdit") > -1) {

                    r1 = new Regex(@"(?<=:).*");
                    DevExpress.XtraEditors.Repository.RepositoryItemCalcEdit date =
                             new DevExpress.XtraEditors.Repository.RepositoryItemCalcEdit();
                    if (r1.Match(strcom).Value != "")
                        date.Properties.EditMask = r1.Match(strcom).Value;

                    grid.Columns[i].ColumnEdit = date;
                } else if (strcom.IndexOf("RepositoryItemSpinEdit") > -1) {
                    r1 = new Regex(@"(?<=:).*");
                    DevExpress.XtraEditors.Repository.RepositoryItemSpinEdit lue1 =
                             new DevExpress.XtraEditors.Repository.RepositoryItemSpinEdit();
                    ((System.ComponentModel.ISupportInitialize)(lue1)).BeginInit();
                    if (r1.Match(strcom).Value != "") {
                        if (r1.Match(strcom).Value.IndexOf("p") > -1) {
                            lue1.Increment = (decimal)0.0001;
                            lue1.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
                        } else
                            if (r1.Match(strcom).Value.IndexOf(".") > -1) {
                                Regex r2 = new Regex(@"(?<=\.).*");

                                lue1.Increment = (decimal)Math.Pow(0.1, r2.Match(strcom).Value.Length / 2);
                                lue1.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric;

                            }
                        lue1.Name = ("lue1" + i.ToString());

                        lue1.Properties.EditMask = r1.Match(strcom).Value;
                        lue1.DisplayFormat.FormatString = r1.Match(strcom).Value;
                        lue1.Properties.DisplayFormat.FormatString = r1.Match(strcom).Value;
                        lue1.EditMask = r1.Match(strcom).Value;
                    }
                    gridView1.Columns[i].ColumnEdit = lue1;
                    //if (lue1.Properties.EditMask.IndexOf("p") > -1 || lue1.Properties.EditMask.IndexOf("%") > -1)
                    {
                        gridView1.Columns[i].DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
                        gridView1.Columns[i].DisplayFormat.FormatString = lue1.Properties.EditMask.ToString();




                    }
                    ((System.ComponentModel.ISupportInitialize)(lue1)).EndInit();
                } else if (strcom.IndexOf("RepositoryItemCheckedComboBoxEdit") > -1) {
                    DevExpress.XtraEditors.Repository.RepositoryItemCheckedComboBoxEdit lue1 = new DevExpress.XtraEditors.Repository.RepositoryItemCheckedComboBoxEdit();

                    lue1.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard;
                    grid.Columns[i].ColumnEdit = lue1;
                    //colctrllist.Add(lue1);
                } else {

                    DevExpress.XtraEditors.Repository.RepositoryItemComboBox lue1 = new DevExpress.XtraEditors.Repository.RepositoryItemComboBox();

                    lue1.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard;
                    grid.Columns[i].ColumnEdit = lue1;
                    colctrllist.Add(lue1);

                }

            }
            ((System.ComponentModel.ISupportInitialize)(this.gridControl1)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.gridView1)).EndInit();
            gridView1.BestFitColumns();
        }
コード例 #2
0
 /// <summary>
 /// 设置整形编辑的最小值。
 /// </summary>
 /// <param name="ctlGrid"></param>
 public void SetInt32EditColMinValue(DevExpress.XtraGrid.GridControl xtraGrid, int val)
 {
     foreach (DevExpress.XtraEditors.Repository.RepositoryItem editItem in xtraGrid.RepositoryItems)
     {
         if (string.Compare(editItem.GetType().Name, "RepositoryItemSpinEdit", true) == 0)
         {
             DevExpress.XtraEditors.Repository.RepositoryItemSpinEdit int32Item = editItem as DevExpress.XtraEditors.Repository.RepositoryItemSpinEdit;
             int32Item.MinValue = val;
         }
     }
 }
コード例 #3
0
        /// <summary>
        /// 根据字段的类型名称获取一个XtrGrid 的编辑控件。
        /// </summary>
        /// <param name="fullTypeName"></param>
        /// <param name="isCard"> 如果是卡片编辑的话图片的显示使用PictureEdit的方式。</param>
        /// <returns></returns>
        public DevExpress.XtraEditors.Repository.RepositoryItem createEditItemByCol(string fullTypeName, bool isCard, MB.WinBase.Common.ColumnPropertyInfo propertyInfo)
        {
            DevExpress.XtraEditors.Repository.RepositoryItem item = null;
            switch (fullTypeName)
            {
            case "System.Int16":
                DevExpress.XtraEditors.Repository.RepositoryItemSpinEdit int16Item = new DevExpress.XtraEditors.Repository.RepositoryItemSpinEdit();
                int16Item.IsFloatValue  = false;
                int16Item.EditMask      = "N00";
                int16Item.Mask.MaskType = DevExpress.XtraEditors.Mask.MaskType.Numeric;
                item = int16Item;
                if (propertyInfo != null)
                {
                    if (propertyInfo.MinValue > Int32.MinValue)
                    {
                        int16Item.MinValue = System.Convert.ToInt16(propertyInfo.MinValue);
                    }
                    if (propertyInfo.MaxValue < Int32.MaxValue)
                    {
                        int16Item.MaxValue = System.Convert.ToInt16(propertyInfo.MaxValue);
                    }
                }
                break;

            case "System.Int32":
                item = CreateEditItemInt32(propertyInfo);
                break;

            case "System.Decimal":
                DevExpress.XtraEditors.Repository.RepositoryItemCalcEdit deciItem = new XtraRepositoryItemCalcEditEx();
                deciItem.MaxLength = 12;    //初不设置的一个数,需要修改;
                item = deciItem;
                break;

            case "System.DateTime":
                DevExpress.XtraEditors.Repository.RepositoryItemDateEdit dateItem = new DevExpress.XtraEditors.Repository.RepositoryItemDateEdit();
                dateItem.NullDate   = DateTime.MinValue;
                dateItem.NullText   = string.Empty;
                dateItem.AutoHeight = false;
                item = dateItem;
                break;

            case "System.Boolean":     //目前Boolean 先用CheckedBox 来表达,如果需要再修改为Group Radio
                DevExpress.XtraEditors.Repository.RepositoryItemCheckEdit boolItem = new DevExpress.XtraEditors.Repository.RepositoryItemCheckEdit();
                item = boolItem;
                break;

            case "System.Byte[]":
                if (!isCard)
                {
                    DevExpress.XtraEditors.Repository.RepositoryItemImageEdit imageItem = new DevExpress.XtraEditors.Repository.RepositoryItemImageEdit();
                    //imageItem.NullText = "";
                    item = imageItem;
                }
                else
                {
                    DevExpress.XtraEditors.Repository.RepositoryItemPictureEdit picItem = new DevExpress.XtraEditors.Repository.RepositoryItemPictureEdit();
                    item = picItem;
                }
                break;

            default:
                DevExpress.XtraEditors.Repository.RepositoryItemTextEdit txtItem = new DevExpress.XtraEditors.Repository.RepositoryItemTextEdit();
                item = txtItem;
                break;
            }
            return(item);//new DevExpress.XtraEditors.Repository.RepositoryItemTextEdit();
        }