Setting height for table in iTextSharp - c#

I've created a table with 2 columns. In the second cell of the first row I want to insert another table that have only one cell. The problem is that I can't set the height of the second table. It stretches more than the content height. Its height is equal with the cell height where it was added.

Table's height depends on its parent container. So you should set height of the parent cell. You can do this in two ways:
cell.MinimumHeight = 50f;
or
cell.FixedHeight = 70f;

The height of the table cannot be set, the height of the table is determined by the height of its cells (you can set the height-property of a cell). You could add an empty cell to the second table if you want to stretch this table.

Related

How to set the max height for datagridview row while using autoresize?

I want to resize the row height of DataGridView based upon height of individual cells in a row.
For which I am using
dt_grid.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
but I also want to limit it to a maximum size beyond which it shouldn't increase the row height.
I believe it is not supported by DataGridView. You can either set AutoSizeRowsMode as you did, or have the content in one line and truncatenated at the end of column(s) width.
However, there's a workaround you can use to achive a very similar effect you're asking for. Let's say you have a Description column, which causes you a trouble. Then, if you set the column to AllCells, you can truncatenate it in the source, i.e. in SQL this way:
SELECT ID, CASE
WHEN LEN(Description) > 150 -- check length
THEN CONCAT(SUBSTRING(Description,1,150),'...') -- truncatenate, if needed
ELSE Description -- else keep it as is
END
FROM MyTable;
You won't get the long text precisely finishing to a pixel, but it will be totally fine and not intereferring with user experience.

Table Row Border - Migradoc

I am creating one table with migradoc. I need to give row border but not in each cells. So i need only outer border.
Code:
Row row = source.AddRow();
row.Borders.Width = 0.2;
row.Borders.Color = Colors.Black;
Here is my existing code. With this i got border for all cells. Please help to avoid border in each cells
you can set width for specific border like
yourrow.yourcell[0].Borders.Left.Width = 1.5;
following above example you can set width for required border separately but if you want to set width for all four border at once you use table.SetEdge method like
// Set the borders of the specified cell range
table.SetEdge(5, this.table.Rows.Count - 4, 1, 4, Edge.Box, BorderStyle.Single, 0.75);
for more information have a look on MigraDoc example
You can set each border (left, right, top, bottom) for each cell independently.
You can use the SetEdge method of the Table class to make things easier.
See also (search for SetEdge):
http://pdfsharp.net/wiki/HelloMigraDoc-sample.ashx

Get height of row where the cells have WrapText set

I am trying to compute the height of the row I'm inserting into my excel sheet. The row's cells are formatted with WrapText=true, so the height of the row is not fixed.
Accessing row.Height will return null.
I was thinking of using something similar to Graphics.MeasureString where I also specify the width constraint in order to retrieve the height.
Didn't find any relevant info online. Any help would be appreciated.
See my post here using Graphics.MeasureString. It works very well.
Autofit Row Height of Merged Cell in EPPlus

How can I change the row height some particular row in DataGridView?

I have a grid view..in that i have a image column..
when ever image coming to image column i want to increase my row height programatically
How can I change the row height some particular row in DataGridView?
I think you are looking for AutoSizeMode
DataGridViewColumn column = dataGridView.Columns[2];
column.AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
This will automaticly size it to fit.
You can use DataGridViewRow.Height property:
myGrid.CurrentRow.Height = someValue;

Unable to change the gridview column width programatically

On my windows form, I need to programatically set the width of columns in the grid view. I am using the following code:
this.dgridv.Columns[columnName].Width = columnWidth;
The above stmt runs without any error. But, the column width remains unchanged. If I insert a breakpoint and check the value of width after the stmt runs, it is still 100, which I guess is the default value of datagrid column width.
Is there something else I need to do apart from this? Are there any values I need to set before changing the column width?
Any help or pointers on this are highly appreciated.
Thanks :)
Have you got the AutoSizeColumnsMode set to Fill?
If you have you'll need to set the FillWeight property instead. This isn't a simple width but the proportion of width / no. columns that this column takes up.
If you haven't resized the columns it will be 100.0.
If the column has been widened it will be > 100.0.
If the column has been shrunk it will be < 100.0.
Widening one column, by definition, shrinks the rest.
This worked:
this.dgridv.Columns[columnName].AutoSizeMode= DataGridViewAutoSizeColumnMode.None;
this.dgridv.Columns[columnName].Width = columnWidth;
To reset it back, I am using:
dgvCol.AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
dataGridView1.Columns[index].Width = 150;
This line of code will set the column width programatically.

Categories