SharpLeaf Tutorials > Table Tutorials > Table Cyclic Settings

Table Cyclic Settings

Column-wise, row-wise, and cell-wise settings are cycled through as we append cells to the Table.

Table Cyclic Settings

When a setting is changed, the argument is used as a cycle, starting at current cell, and will be applied whenever we create a cell or change the content of an existing one.

Cell-wise settings can be set for as a scalar (for all future cells), as vector (along with a boolean flag specifying whether it is a row-wise or a column-wise cycle), or as a matrix (for tiling with a rectangular array of settings).

Column-wise and Row-wise settings can be set as scalar (for all future columns/rows), or as a vector to cycle through. For convenience, the default behaviour is that the setting is applied only the first time we create a cell in that row/column – otherwise things get pretty complicated when we re-visit columns in future rows or rows in future columns if we used several cycles (see example below). The ColumnOverwrite and RowOverwrite may be set to true (temporarily or not), to force the overwrite the column/row settings when creating or changing a cell.


   quarters = new string[]{"Q1","Q1","Q1","Q2","Q2","Q2","Q3","Q3","Q3","Q4","Q4","Q4"};
   months = new string[]{"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct",
   entries = new string[]{"Suspenders","Pillows","Garden gnomes","Hair curlers","Pop "+
            "corn","Door mats","Firecrackers","Lemon squeezers"};
   notes = new string[]{"","","Febrile activity","","Temporary closure in March","",
            "Seasonal activity",""};
   figures = new string[][] {new string[]{"36.1","59.5","20.6","45","63.7","50","26.1",
            "10.9","50.6","64.6","60.2","68.1"},new string[]{"78.3","66.9","72.4",
            "12.2","11","10.15"},new string[]{"49.1","25.5","40.8","31.5","61","64.2",
            "58.1","32.5","66.9","28.1","33.4","48.2"},new string[]{"56.5","96","-",
            "63.3","56.1","77.1"},new string[]{"86","51.1","12.05","23.8","41.5",
            "44.7","81.4","47.9","22.6","47.9","51.9","90"},new string[]{"23.4","27.2",

   titlefont = new FontType("Times",10,FontStyle.Bold);
   entryfont = new FontType("Times",10);
   figfont = new FontType("Arial",8);
   notefont = new FontType("Times",8);

  // Table-wide settings
   tb = new Table();
  // Set up row and column grid for whole table
   tb.SetRowGrid(new double[] {0,0.1,0,0,0,0.1,0,0,0});  // no gridline after first 
            row, then every fourth row (last row has table box)
   tb.SetColumnGrid(0);  // disable vertical grid
  // Set column-wise cell box for whole table
   box0 = new BoxStyle(0,Color.Transparent,LineStyle.Invisible,0,Color.LightGray,
   box1 = new BoxStyle(0,Color.Transparent,LineStyle.Invisible,0,Color.LightBlue,
   box2 = new BoxStyle(0,Color.Transparent,LineStyle.Invisible,0,Color.PaleGreen,
   box3 = new BoxStyle(0,Color.Transparent,LineStyle.Invisible,0,
   box4 = new BoxStyle(0,Color.Transparent,LineStyle.Invisible,0,Color.Tan,
   tb.SetCellBox(new BoxStyle[]{box0,box1,box1,box1,box2,box2,box2,box3,box3,box3,box4,
  // Similarly, we could call SetColumnWidths for the whole table at once,
  // but we're going to do it as we go through columns for the first time,
  // just to emphase that column and row settings are not overwritten by default

  // Fill the first row
   tb.SetRowMerge(true);  // Merge quarters horizontally
   tb.SetCellFont(titlefont);  // Font for next cells
   tb.SetCellAlignment(Alignment.Left);  // Merged cells will be centered
  // This is the first time we go through columns, so their column settings will be 
            carved in stone as we go
  // (unless we later call SetColumnOverwrite(true) before adding cell content to some 
            existing columns)
   tb.SetColumnWidths(0);  // First column is auto-fit
   tb.SetColumnWidths(30);  // Data columns have fixed width
   tb.SetColumnWidths(-1);  // Last column takes remaining width
  // The default SetColumnOverwite(false) ensures that the current SetColumnWidths cycle
  // won't overwrite previous columns widths as we re-visit them in other rows.

  // Fill the second row
   tb.NextRow(1);  // Next row, first column
   tb.SetRowMerge(false);  // Disable row merging for the rest of the table

  // Fill the first column
   tb.NextRow(1);  // Next row, first column
   tb.SetCellFont(entryfont);  // Font for next cells
   tb.SetCellFillChar('.');  // Set up fill character for row titles
   tb.AddColumns(entries);  // Flow row titles (and move on to start of next column)
   tb.SetCellFillChar(' ');  // Disable fill character for the rest of the table

  // Flow figures
   tb.AddRows(figures);  // Will move cell pointer to next row

  // Finish with a column of notes
   tb.NextEmptyColumn(3);  // Next empty column starting at third row


See also ...

Table Tutorials | Table Glossary | Table Members

Send comments on this topic
© Dyalog Ltd 2016