Hi,I was unable to use FitElement to get it working - I had 2+ rows to keep together.
What I ended up doing was adding just one row to the datatable for each of the "rows" I had and using "\r\n" to put the next virtual "row"
on a new line:
Example:
string lcCol0 = "Row 1 Col 1 Text";
string lcCol1 = "Row 1 Col 2 Text";
lcCol0 += "\r\n" + "Row 2 Col 1 Text";
lcCol1 += "\r\n" + "Row 2 Col 2 Text";
lcCol0 += "\r\n" + "Row 3 Col 1 Text";
lcCol1 += "\r\n" + "Row 3 Col 2 Text";
DataTable loTableData = new DataTable();
loTableData.Columns.Add("Col1");
loTableData.Columns.Add("Col2");
loTableData.Rows.Add(new string[] { lcCol0, lcCol1 } );
Then for the Grid I used a BeginCellLayout:
PdfGrid moGrid = new PdfGrid();
moGrid.DataSource = loTableData;
moGrid.BeginCellLayout += moGrid_BeginCellLayout;
The benefit of this was I was able to bold certain strings within the text using BeginCellLayout and PdfHTMLTextElement,
It also allowed me to draw a border at the top and using BeginCellLayout I had to fudge the border - It was too close to the top.
Below is my BeginCellLayout for my specific need, I only needed to do it for col 6:
private static PdfFont moFont10 = new PdfTrueTypeFont(new Font("Calibri", 10), true);
public static void moGrid_BeginCellLayout(object sender, PdfGridBeginCellLayoutEventArgs args)
{
PdfHTMLTextElement textElement = new PdfHTMLTextElement();
textElement.Font = moFont10;
if (args.CellIndex == 6)
{
if (args.Value != "Event category, Consequence and event description")
{
float lnX = args.Bounds.X;
float lnY = args.Bounds.Y;
float lnL = args.Bounds.Left;
float lnT = args.Bounds.Top;
float lnW = args.Bounds.Width;
float lnH = args.Bounds.Bottom;
args.Skip = true;
textElement.HTMLText = args.Value;
args.Graphics.DrawRectangle(PdfPens.Black, lnL, lnT + 1, lnW, 0);
textElement.Draw(args.Graphics, new RectangleF(lnX, lnY+4, lnW, lnH + 4));
}
}
}
There was one little gotcha in the BeginCellLayout when I moved the textElement down by "4" the end of the text
moved down as well, so in the Col6 in the datatable I had to append "\r\n" + "\r\n" at the end of a text.
Anyway - It works and the plus is it allows me to use HTML formatting in the text.
Thanks again for your help - just leaving this update in case anyone needs a similar solution.
Cheers,
Matt