Matrix - Fixed number of columns

TurntwoTurntwo Folsom, CA
edited 1:32PM in FastReport .NET
Is there any way to create a Matrix with a fixed number of columns? I want to put several Matrixes on the same report where the columns line up - but each Matrix has a different number of columns based on different grouping.

Another option that could also work would be the ability to have the Matrix be a fixed size, and the columns take up the available space equally (then at the least the Total columns would line up).

Thanks,

Jason

Comments

  • edited 1:32PM
    Hello,

    You may access the prepared matrix and do something with its columns (hide some, or adjust width). See the attached example which you can run from the Demo.exe.
  • TurntwoTurntwo Folsom, CA
    edited 1:32PM
    Thanks - that is helpful. I've managed to get the Matrix to extend the width of the screen now.

    I tried adding columns, and the columns are included (the Columns.Count is higher), but the Columns don't display. What do I have to set to get the added columns to display.

    I added them with Matrix1.ResultTable.Columns.Add(new TableColumn());

    I also tried,
    TableColumn col = new TableColumn();
    col.Visible = true;
    col.MaxWidth = 200;
    col.Width = 100;
    Matrix1.ResultTable.Columns.Add(col);
  • TurntwoTurntwo Folsom, CA
    edited October 2011
    OK - kinda figured it out on my own (posting here for others who have similar requirements).

    Using Matrix1.Data.AddValues(), I could add columns of blank values. I wanted to add columns of 0.00 values, but the ManualBuild didn't have the calculated rows available to work with, and I think I needed the headings to get the 0s to show. I tried using AddValues in ModifyResult, but it didn't change anything. With blank values, the only issue I had was getting the blank headers at the end instead of the beginning, and I think I could have figured that out.

    Instead I left the extra areas blank by changing the column widths to a fixed value, and then calculating the width for the Total column (right-justified), as the remaining space (needed to increase the MaxWidth also). This lines up the columns across the different Matrixes, stretches them across the available area and gives me the look I needed (except missing the 0 columns, which is just clutter anyway).

    Thanks for the help.
    private void Matrix4_ModifyResult(object sender, EventArgs e)
        {
          Matrix4.ResultTable.AfterCalcBounds += new EventHandler(ResultTable_AfterCalcBounds);
        }
    
        private void Matrix5_ModifyResult(object sender, EventArgs e)
        {
          Matrix5.ResultTable.AfterCalcBounds += new EventHandler(ResultTable_AfterCalcBounds);
        }
        
        private void ResultTable_AfterCalcBounds(object sender, EventArgs e)
        {
          TableResult resultTable = sender as TableResult;
          float headerWidth = 915f;
          float colWidth = headerWidth/8; // 915 is width of header bar, make room for 8 columns
          
          foreach (TableColumn column in resultTable.Columns)
          {
            column.AutoSize = false;
            column.Width = colWidth;
          }
          
          // Set Total column width to remaining space
          resultTable.Columns[resultTable.ColumnCount-1].MaxWidth = headerWidth;
          resultTable.Columns[resultTable.ColumnCount-1].Width = headerWidth - (colWidth * (resultTable.ColumnCount-1));
          
          // this will recalculate table rows height
          resultTable.CalcHeight();
        }
    

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.