/// <summary>
        /// 功能描述:加载column
        /// 作  者:HZH
        /// 创建日期:2019-08-08 17:51:50
        /// 任务编号:POS
        /// </summary>
        private void LoadColumns()
        {
            try
            {
                if (DesignMode)
                {
                    return;
                }

                ControlHelper.FreezeControl(this.panHead, true);
                this.panColumns.Controls.Clear();
                this.panColumns.ColumnStyles.Clear();

                if (m_columns != null && m_columns.Count() > 0)
                {
                    int intColumnsCount = m_columns.Count();
                    if (m_isShowCheckBox)
                    {
                        intColumnsCount++;
                    }
                    this.panColumns.ColumnCount = intColumnsCount;
                    for (int i = 0; i < intColumnsCount; i++)
                    {
                        Control c = null;
                        if (i == 0 && m_isShowCheckBox)
                        {
                            this.panColumns.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(SizeType.Absolute, 30F));

                            UCCheckBox box = new UCCheckBox();
                            box.TextValue           = "";
                            box.Size                = new Size(30, 30);
                            box.CheckedChangeEvent += (a, b) =>
                            {
                                Rows.ForEach(p => p.IsChecked = box.Checked);
                                if (HeadCheckBoxChangeEvent != null)
                                {
                                    HeadCheckBoxChangeEvent(a, b);
                                }
                            };
                            c = box;
                        }
                        else
                        {
                            var item = m_columns[i - (m_isShowCheckBox ? 1 : 0)];
                            this.panColumns.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(item.WidthType, item.Width));
                            Label lbl = new Label();
                            lbl.Name       = "dgvColumns_" + i;
                            lbl.Text       = item.HeadText;
                            lbl.Font       = m_headFont;
                            lbl.ForeColor  = m_headTextColor;
                            lbl.TextAlign  = ContentAlignment.MiddleCenter;
                            lbl.AutoSize   = false;
                            lbl.Dock       = DockStyle.Fill;
                            lbl.MouseDown += (a, b) =>
                            {
                                if (HeadColumnClickEvent != null)
                                {
                                    HeadColumnClickEvent(a, b);
                                }
                            };
                            c = lbl;
                        }
                        this.panColumns.Controls.Add(c, i, 0);
                    }
                }
            }
            finally
            {
                ControlHelper.FreezeControl(this.panHead, false);
            }
        }
        public void ReloadCells()
        {
            try
            {
                ControlHelper.FreezeControl(this, true);
                this.panCells.Controls.Clear();
                this.panCells.ColumnStyles.Clear();

                int intColumnsCount = Columns.Count();
                if (Columns != null && intColumnsCount > 0)
                {
                    if (IsShowCheckBox)
                    {
                        intColumnsCount++;
                    }
                    this.panCells.ColumnCount = intColumnsCount;
                    for (int i = 0; i < intColumnsCount; i++)
                    {
                        Control c = null;
                        if (i == 0 && IsShowCheckBox)
                        {
                            this.panCells.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(SizeType.Absolute, 30F));

                            UCCheckBox box = new UCCheckBox();
                            box.Name                = "check";
                            box.TextValue           = "";
                            box.Size                = new Size(30, 30);
                            box.Dock                = DockStyle.Fill;
                            box.CheckedChangeEvent += (a, b) =>
                            {
                                IsChecked = box.Checked;
                                if (CheckBoxChangeEvent != null)
                                {
                                    CheckBoxChangeEvent(a, new DataGridViewEventArgs()
                                    {
                                        CellControl = box,
                                        CellIndex   = 0
                                    });
                                }
                            };
                            c = box;
                        }
                        else
                        {
                            var item = Columns[i - (IsShowCheckBox ? 1 : 0)];
                            this.panCells.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(item.WidthType, item.Width));

                            Label lbl = new Label();
                            lbl.Tag        = i - (IsShowCheckBox ? 1 : 0);
                            lbl.Name       = "lbl_" + item.DataField;
                            lbl.Font       = new Font("微软雅黑", 12);
                            lbl.ForeColor  = Color.Black;
                            lbl.AutoSize   = false;
                            lbl.Dock       = DockStyle.Fill;
                            lbl.TextAlign  = item.TextAlign;
                            lbl.MouseDown += (a, b) =>
                            {
                                Item_MouseDown(a, b);
                            };
                            c = lbl;
                        }
                        this.panCells.Controls.Add(c, i, 0);
                    }
                }
            }
            finally
            {
                ControlHelper.FreezeControl(this, false);
            }
        }
示例#3
0
        /// <summary>
        /// 添加单元格元素,仅做添加控件操作,不做数据绑定,数据绑定使用BindingCells
        /// </summary>
        public void ReloadCells()
        {
            try
            {
                ControlHelper.FreezeControl(this, true);
                this.panCells.Controls.Clear();
                this.panCells.ColumnStyles.Clear();

                int intColumnsCount = Columns.Count();
                if (Columns != null && intColumnsCount > 0)
                {
                    if (IsShowCheckBox)
                    {
                        intColumnsCount++;
                    }
                    this.panCells.ColumnCount = intColumnsCount;
                    bool blnFirst = true;
                    for (int i = 0; i < intColumnsCount; i++)
                    {
                        Control c = null;
                        if (i == 0 && IsShowCheckBox)
                        {
                            this.panCells.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(SizeType.Absolute, 30F));

                            UCCheckBox box = new UCCheckBox();
                            box.Name      = "check";
                            box.TextValue = "";
                            box.Size      = new Size(30, 30);
                            box.Dock      = DockStyle.Fill;
                            c             = box;
                        }
                        else
                        {
                            var item = Columns[i - (IsShowCheckBox ? 1 : 0)];
                            var w    = item.Width - (blnFirst ? (this.panLeft.Width / 2 * rowLevel) : 0);
                            if (w < 5)
                            {
                                w = 5;
                            }
                            this.panCells.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(item.WidthType, w));
                            blnFirst = false;
                            if (item.CustomCellType == null)
                            {
                                Label lbl = new Label();
                                lbl.Tag        = i - (IsShowCheckBox ? 1 : 0);
                                lbl.Name       = "lbl_" + item.DataField;
                                lbl.Font       = new Font("微软雅黑", 12);
                                lbl.ForeColor  = Color.Black;
                                lbl.AutoSize   = false;
                                lbl.Dock       = DockStyle.Fill;
                                lbl.TextAlign  = item.TextAlign;
                                lbl.MouseDown += (a, b) =>
                                {
                                    Item_MouseDown(a, b);
                                };
                                c = lbl;
                            }
                            else
                            {
                                Control cc = (Control)Activator.CreateInstance(item.CustomCellType);
                                cc.Dock = DockStyle.Fill;
                                c       = cc;
                            }
                        }
                        this.panCells.Controls.Add(c, i, 0);
                    }
                }
            }
            finally
            {
                ControlHelper.FreezeControl(this, false);
            }
        }