Hoping someone out there might have had the same issue as this and have found a resolution.
I'm trying to set certain rows within a table to be grouped so that if a row falls into the next page the other rows will also go across to that next page.
I'm using PdfSharp and Migradoc setting the rows KeepWith property to the index of the row i want to keep attached to.
IE:
var row = myTable.AddRow();
var rowIndex =开发者_开发技巧 row.Index;
foreach (var term in terms)
{
row = myTable.AddRow();
if (term.name == "group")
{
row.KeepWith = rowIndex;
}
}
When i try and load the pdf I get an 'Object reference not set to an instance of an object' error thrown and cannot figure out why. Any help would be great.
Set KeepWith to the count of following rows you want to keep with the current row. To keep three rows together, the correct value is 2 (set at the first row of the group).
I was making the mistake of putting the KeepWith at the end of the rows to keep together. As Vive la déraison said, place the KeepWith on the first row of the rows to keep together.
Additionally, the int provided for the KeepWith value does NOT include the row it is set on. So to keep rows rowA, rowB, and rowC together, you would set:
rowA.KeepWith = 2;
If you're setting a KeepWith for the last rows of your table, and accidentally set the value +1 (Inclusive of the row you set it on), you will get the same "Object Not Set..." error, as you are extending the KeepWith longer than the table rows.
Gotta love those Off-By-One errors.
精彩评论