/// <summary> /// Reloads the cells. /// </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; 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() { RowIndex = this.RowIndex, 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)); 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); } }
/// <summary> /// 功能描述:加载column /// </summary> private void LoadColumns() { try { if (DesignMode) { return; } ControlHelper.FreezeControl(this.panHead, true); this.panRow.Controls.Clear(); 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); } }