예제 #1
0
 private void setFormatFlags()
 {
     format.Alignment = TextHelper.TranslateAligment(TextAlign);
     format.Trimming  = trimming;
 }
예제 #2
0
        /// <summary>
        /// Create summary boxes for each Column of the DataGridView
        /// </summary>
        private void reCreateSumBoxes()
        {
            ReadOnlyTextBox sumBox;

            foreach (Control control in sumBoxHash.Values)
            {
                this.Controls.Remove(control);
            }
            sumBoxHash.Clear();

            int iCnt = 0;

            List <DataGridViewColumn> sortedColumns = SortedColumns;

            foreach (DataGridViewColumn dgvColumn in sortedColumns)
            {
                sumBox = new ReadOnlyTextBox();
                sumBoxHash.Add(dgvColumn, sumBox);

                sumBox.Top         = 0;
                sumBox.Height      = dgv.RowTemplate.Height;
                sumBox.BorderColor = dgv.GridColor;
                if (summaryRowBackColor == null)
                {
                    sumBox.BackColor = dgv.DefaultCellStyle.BackColor;
                }
                else
                {
                    sumBox.BackColor = summaryRowBackColor;
                }
                sumBox.BringToFront();

                if (dgv.ColumnCount - iCnt == 1)
                {
                    sumBox.IsLastColumn = true;
                }

                if (dgv.SummaryColumns != null && dgv.SummaryColumns.Length > 0)
                {
                    for (int iCntX = 0; iCntX < dgv.SummaryColumns.Length; iCntX++)
                    {
                        if (dgv.SummaryColumns[iCntX] == dgvColumn.DataPropertyName ||
                            dgv.SummaryColumns[iCntX] == dgvColumn.Name)
                        {
                            dgvColumn.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;

                            dgvColumn.CellTemplate.Style.Format = dgv.FormatString;
                            sumBox.TextAlign = TextHelper.TranslateGridColumnAligment(dgvColumn.DefaultCellStyle.Alignment);
                            sumBox.IsSummary = true;

                            sumBox.FormatString = dgvColumn.CellTemplate.Style.Format;
                            if (dgvColumn.ValueType == typeof(System.Int32) || dgvColumn.ValueType == typeof(System.Int16) ||
                                dgvColumn.ValueType == typeof(System.Int64) || dgvColumn.ValueType == typeof(System.Single) ||
                                dgvColumn.ValueType == typeof(System.Double) || dgvColumn.ValueType == typeof(System.Single) ||
                                dgvColumn.ValueType == typeof(System.Decimal))
                            {
                                sumBox.Tag = System.Activator.CreateInstance(dgvColumn.ValueType);
                            }
                        }
                    }
                }

                sumBox.BringToFront();
                this.Controls.Add(sumBox);

                iCnt++;
            }

            if (dgv.DisplaySumRowHeader)
            {
                sumRowHeaderLabel.Font      = new Font(dgv.DefaultCellStyle.Font, dgv.SumRowHeaderTextBold ? FontStyle.Bold : FontStyle.Regular);
                sumRowHeaderLabel.Anchor    = AnchorStyles.Top;
                sumRowHeaderLabel.TextAlign = ContentAlignment.MiddleLeft;
                sumRowHeaderLabel.Height    = sumRowHeaderLabel.Font.Height;
                sumRowHeaderLabel.Top       = Convert.ToInt32(Convert.ToDouble(this.InitialHeight - sumRowHeaderLabel.Height) / 2F);
                sumRowHeaderLabel.Text      = dgv.SumRowHeaderText;

                sumRowHeaderLabel.ForeColor = dgv.DefaultCellStyle.ForeColor;
                sumRowHeaderLabel.Margin    = new Padding(0);
                sumRowHeaderLabel.Padding   = new Padding(0);

                this.Controls.Add(sumRowHeaderLabel);
            }
            calcSummaries();
            resizeSumBoxes();
        }