Cell in matrix

edited 4:47AM in FastReport .NET
Hello
please help
How can I make a cell conform to a text in a matrix

thanks

Comments

  • edited June 2018
    your question is not clear, here is the code to create matrix from code
                // report object
                FastReport.Report report = new FastReport.Report();
    
                // add report page
                FastReport.ReportPage page = new FastReport.ReportPage();
    
                // set page margin
                report.Pages.Add(page);
                page.CreateUniqueName();
                page.LeftMargin = 10;
                page.RightMargin = 10;
                page.TopMargin = 10;
                page.BottomMargin = 10;
                page.UnlimitedWidth = true;
    
                // create data band
                FastReport.DataBand dataBand = new FastReport.DataBand();
                page.Bands.Add(dataBand);
                dataBand.CreateUniqueName();
                dataBand.Height = FastReport.Utils.Units.Centimeters * 2.3f;
    
                FastReport.Matrix.MatrixObject matrix = new FastReport.Matrix.MatrixObject();
                matrix.Parent = dataBand;
                matrix.CreateUniqueName();
                matrix.Bounds = new RectangleF(FastReport.Utils.Units.Centimeters * 0.1f, FastReport.Utils.Units.Centimeters * 0.1f, FastReport.Utils.Units.Centimeters * 8f, FastReport.Utils.Units.Centimeters * 2f);
                matrix.CellsSideBySide = true;
                matrix.DataSource = report.GetDataSource("MatrixDemo");
                matrix.Style = "blue";
    
                // create one column descriptor
                FastReport.Matrix.MatrixHeaderDescriptor column = new FastReport.Matrix.MatrixHeaderDescriptor("[MatrixDemo.Year]");
                matrix.Data.Columns.Add(column);
    
                // create one row descriptor
                FastReport.Matrix.MatrixHeaderDescriptor row = new FastReport.Matrix.MatrixHeaderDescriptor("[MatrixDemo.Name]");
                matrix.Data.Rows.Add(row);
    
                // create three data cells
                FastReport.Matrix.MatrixCellDescriptor cell1 = new FastReport.Matrix.MatrixCellDescriptor("[MatrixDemo.ItemsSold]", FastReport.Matrix.MatrixAggregateFunction.Sum);
                matrix.Data.Cells.Add(cell1);
                FastReport.Matrix.MatrixCellDescriptor cell2 = new FastReport.Matrix.MatrixCellDescriptor("[MatrixDemo.Revenue]", FastReport.Matrix.MatrixAggregateFunction.Sum);
                matrix.Data.Cells.Add(cell2);
                FastReport.Matrix.MatrixCellDescriptor cell3 = new FastReport.Matrix.MatrixCellDescriptor("0", FastReport.Matrix.MatrixAggregateFunction.Sum);
                matrix.Data.Cells.Add(cell3);
    
                // build matrix template
                matrix.BuildTemplate();            
    
                // important!!! formatting is available after 'BuildTemplate'
                FastReport.Format.NumberFormat numberFormat = new FastReport.Format.NumberFormat();
                numberFormat.UseLocale = false;
                numberFormat.GroupSeparator = ",";
                numberFormat.DecimalSeparator = ".";
                numberFormat.DecimalDigits = 2;
                numberFormat.NegativePattern = 1;
    
                for (int i = 2; i < 4; i++)
                {
                    for (int j = 1; j < 7; j++)
                    {
                        matrix.Rows[i][j].Format = numberFormat;
                    }
                }
    
                // change header text
                FastReport.Table.TableCell tableCell = (FastReport.Table.TableCell)matrix.Rows[0][0];
                tableCell.Text = "Employee";
                tableCell = (FastReport.Table.TableCell)matrix.Rows[1][1];
                tableCell.Text = "Qty";
                tableCell = (FastReport.Table.TableCell)matrix.Rows[1][2];
                tableCell.Text = "Amount";
                tableCell = (FastReport.Table.TableCell)matrix.Rows[1][3];
                tableCell.Text = "Amount / Qty";
                tableCell = (FastReport.Table.TableCell)matrix.Rows[1][4];
                tableCell.Text = "???? Qty";
                tableCell = (FastReport.Table.TableCell)matrix.Rows[1][5];
                tableCell.Text = "???? Amount";
                tableCell = (FastReport.Table.TableCell)matrix.Rows[1][6];
                tableCell.Text = "???? (Amount / Qty)";
    
                // autosize column
                for (int i = 0; i < 7; i++)
                {
                    matrix.Columns[i].AutoSize = true;
                }
    
                // assign an event on table cell
                tableCell = (FastReport.Table.TableCell)matrix.Rows[2][3];
                tableCell.BeforePrintEvent = "Cell18_BeforePrint";
                tableCell = (FastReport.Table.TableCell)matrix.Rows[2][6];
                tableCell.BeforePrintEvent = "Cell21_BeforePrint";
                tableCell = (FastReport.Table.TableCell)matrix.Rows[3][3];
                tableCell.BeforePrintEvent = "Cell25_BeforePrint";
                tableCell = (FastReport.Table.TableCell)matrix.Rows[3][6];
                tableCell.BeforePrintEvent = "Cell28_BeforePrint";
    
                report.ScriptText = @"using System;
    using FastReport;
    namespace FastReport
    {
        public class ReportScript
        {
            private void Cell18_BeforePrint(object sender, EventArgs e)
            {
                if (Cell16.Value != null && Cell17.Value != null)
                {
                    double sumQty = (double)((int)Cell16.Value);
                    double sumAmount = (double)((decimal)Cell17.Value);
                    double sumAverage = sumAmount / sumQty;
                    Cell18.Text = sumAverage.ToString(""#,##0.00"");
                }
            }
            private void Cell21_BeforePrint(object sender, EventArgs e)
            {
                if (Cell19.Value != null && Cell20.Value != null)
                {
                    double sumQty = (double)((int)Cell19.Value);
                    double sumAmount = (double)((decimal)Cell20.Value);
                    double sumAverage = sumAmount / sumQty;
                    Cell21.Text = sumAverage.ToString(""#,##0.00"");
                }
            }
            private void Cell25_BeforePrint(object sender, EventArgs e)
            {
              if (Cell23.Value != null && Cell24.Value != null)
              {
                double sumQty = (double)((int)Cell23.Value);
                double sumAmount = (double)((decimal)Cell24.Value);
                double sumAverage = sumAmount / sumQty;
                Cell25.Text = sumAverage.ToString(""#,##0.00"");
              }
            }
            private void Cell28_BeforePrint(object sender, EventArgs e)
            {
                if (Cell26.Value != null && Cell27.Value != null)
                {
                    double sumQty = (double)((int)Cell26.Value);
                    double sumAmount = (double)((decimal)Cell27.Value);
                    double sumAverage = sumAmount / sumQty;
                    Cell28.Text = sumAverage.ToString(""#,##0.00"");
                }
            }
        }
    }";
    
  • edited June 2018
    ok thanks for you answer

    my problem is how i can do for that a cell this is adjust to a text

    example

    if a text is small the cell this is small
    if a text is big the cell this is big

    i use autosize

    but this is duplicate fields and the table this is breaks

    i want is that a table this is fill sending the values from a program


    thanks
  • edited June 2018
    set: page.UnlimitedWidth = true;

    // autosize column
    for (int i = 0; i < 7; i++)
    {
    matrix.Columns.AutoSize = true;
    }
  • edited 4:47AM
    thanks very much

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.