PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

Keeping tables together
https://forum.pdfsharp.net/viewtopic.php?f=2&t=84
Page 1 of 1

Author:  chrisb [ Sat Feb 24, 2007 3:31 pm ]
Post subject:  Keeping tables together

Hi,
I'm building up an expenditure report that has many costs, which has the following layout

Cost Type1
cost x
cost x
cost x
total xx

Cost Type2
cost x
cost x
cost x
total xx

Grand total xxx

I want to keep all of the costs together with their 'parent' cost type, so that i don't end up with a few rows spilling over on to the next page.

The approach i've taken is to add a new table to the same section each time i lay out a block of cost types, setting the keeptogether property to true, and adding a new row to the table each time i write a cost. However, i just can't seem to get tables to stay together.

The code i'm using is along the lines of:

private void fillTable(Section section)
{
Row r;

//loop through each cost type
foreach (costType c in CostTypes)
{
Table tblTable = new Table();

//add a table to the section
tblTable = base.AddATable(section);
tblTable.KeepTogether = true;
addColumns(tblTable);

r = tblTable.AddRow();
r.Cells[0].AddParagraph("Cost Type Title");
r.HeadingFormat = true;

//loop through each of the costs that belong to the current cost type
foreach (cost cs in costs)
{
r = tblTable.AddRow();
r.Cell[1].AddParagraph("cost title");
r.Cell[2].AddParagraph("0.00");
}
}
}

Am i missing something?

Thanks,
Chris.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/