I am trying to add a blank row to a table and add a top single black border to the blank row. My code is as follows:
private static void AddBlankRow(Table table)
{
// Clone the last row in the table.
var clonedRow = (Row)table.LastRow.Clone(true);
// Add top border to row
// Remove all content from the cloned row's cells.
// This makes the row ready for new content to be inserted into.
foreach (Cell cell in clonedRow.Cells)
{
cell.CellFormat.Borders.Top.LineStyle = LineStyle.Single;
cell.CellFormat.Borders.Top.Color = Color.Black;
cell.RemoveAllChildren();
cell.EnsureMinimum();
}
// Add the row to the end of the table.
table.AppendChild(clonedRow);
}
I run into an exception on the following line:
cell.CellFormat.Borders.Top.LineStyle = LineStyle.Single;
because cell.CellFormat.Borders.Top.LineStyle has a null reference (in fact so do all of the attribures of Top).
How should I handle this so that I can add the border to the blank row.
Thanks,
David