Tables with rectangles - rectangle does not resize

Tables with rectangles - rectangle does not resize

Forum member · Dec 11, 2009
I have a table where the column headers should not have any borders but the cells should. I understand that I cannot set the borders for individual cells (refer to Forum Thread - How to set table cell border style?). The solution given there is - Currently you can either apply border to all the cells within the table or to none. You can not control borders for individual cells.As a work around you can do this by adding a rectangle to a cell and then specifying the border for the rectangle. You will have to set the padding of the cell and height and width of the rectangle accordingly. So I create a table with borderwidth = 0. For each cell I create a group, add a rectangle and then a TextArea object with the text to display. The problem is that I don't know the height of the row till data has been added to all the cells in the row. So though I create the rectangle the same size as the textarea for the cell, the row increases in height to fit all the data, but the rectangles don't. This is the code I am using - Document doc = new Document(); Page page = new Page(); doc.Pages.Add(page); Table table = new Table(0 + 10, 0, 100, 10); table.BorderWidth = 0; table.Columns.Add(50); table.Columns.Add(50); table.Padding = 0; Row row = table.Rows.Add(); Group g = new Group(); TextArea t = new TextArea("This is a small string", 0, 0, 50, 10); t.Height = t.GetRequiredHeight(); ceTe.DynamicPDF.PageElements.Rectangle rect = new ceTe.DynamicPDF.PageElements.Rectangle(0, 0, 50, t.Height); g.Add(rect); g.Add(t); row.Cells.Add(g); g = new Group(); t = new TextArea("This is a long string that will not fit in the defined height of 10. The cell will resize but the rectangle will not", 0, 0, 50, 10); t.Height = t.GetRequiredHeight(); rect = new ceTe.DynamicPDF.PageElements.Rectangle(0, 0, 50, t.Height); g.Add(rect); g.Add(t); row.Cells.Add(g); page.Elements.Add(table); When you run this - you'll see that the 2 rectangles are of different heights which is not what I want.

Re: Tables with rectangles - rectangle does not resize

Support · Dec 11, 2009
Hello, You are setting two different heights for both the rectangles depending on the text they have respectively. This is the reason for seeing rectangles with different heights and it will not look like aligned properly in a single row. You will have to set the same height to all the rectangles in a row so that they look like same. So you will have to use the maximum height you get from all the text areas as the height for all the rectangles in the row. Thanks, ceTe Software Support Team.