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
Related
I have a long table in C#, MigraDoc, which splits across two pages.
I need only outer borders.
When the table is split, the top border and the bottom border will not be visible.
Is there a way to make them visible?
(It cannot be determined where the page break will be.)
For top border you could use the row.HeadingFormat = true and then set the top border on it like this:
var table = new Table();
var headingRow = table.AddRow();
headingRow.HeadingFormat = true;
headingRow.Borders.Top.Width = 1;
// your other table content here
I'm currently looking into how to do the same thing for the bottom table border, but it seems that there's no way to do it.
It appears as though the PDfPCell class does have a border property on it but not the PdfPTable class.
Is there some property on the PdfPTable class to set the borders of all its contained cells in one statement?
Borders are defined at the level of the cell, not at the level of the table. Hence: if you want to remove the borders of the table, you need to remove the borders of each cell.
By default, each cell has a border. You can change this default behavior by changing the border of each cell. For instance: if you create PdfPCell objects, you use:
cell.setBorder(Rectangle.NO_BORDER);
In case the cells are created internally, you need to change that property at the level of the default cell. See What is the PdfPTable.DefaultCell property used for?
table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
For special borders, for instance borders with rounded corners or a single border for the whole table, or double borders, you can use either cell events or table events, or a combination of both. In Chapter 5 of my book "iText in Action - Second Edition", you'll find a PDF with double borders. See the PressPreviews example to see how this was done. Note that all examples from the book were ported to C#. You can find these examples here.
The official site also has examples where the borders are dotted lines, have rounded corners, and so on.
iTextSharp has no setBorder() method.
I tried the following:
cell.HasBorder(Rectangle.NO_BORDER); // <= this did nothing
cell.BorderColor = BaseColor.WHITE; // <= this works for me, but if your document's background is not white, you might not like it
cell.BorderWidth = 0; // <= this works like gangbusters
So it seems the "safest" way to go is to set BorderWidth to zilch AKA nada.
The following worked for me.
cell.Border = Rectangle.NO_BORDER;
How does one set the alignment of text within a chart legend object? I've tried using:
myChartName.Legends["mySeriesName"].Alignment = stringAlignment.Near
With no effect. I've also tried to create custom legend items, again resulting in no effect. Text is ALWAYS centered (along with the series marker) in the legend "box". The only text I have been able to align is the title, but I don't need titles in my application.
My research to date says the legend object is basically a table with (by default) two cells. If that is the case there should be a way to access those cells and manipulate them as table cells. So, what gives? Why can't I access the text alignment properties of the legend object? Clearly, there is something I'm missing, but for the life of me I can't seem to figure this out. Quite frustrating.
Problem solved. The CustomItem approach wasn't working either, so I tried using the LegendCellColumn Class.
I changed the LegendStyle from Column to Row, then added two CellColumns, one for the series symbol and one for the legend text. Set the alignment, margins, and column widths (that turned out to be the trick), and voila; a legend that looks like I want. Here's the code for anyone with a similar issue.
chartSel.Legends[ySeries.Name].CellColumns.Add(new LegendCellColumn("", LegendCellColumnType.SeriesSymbol, ""));
chartSel.Legends[ySeries.Name].CellColumns[0].Alignment = ContentAlignment.TopLeft;
chartSel.Legends[ySeries.Name].CellColumns[0].Margins = new System.Windows.Forms.DataVisualization.Charting.Margins(0, 0, 1, 1);
chartSel.Legends[ySeries.Name].CellColumns[0].MinimumWidth = 250;
chartSel.Legends[ySeries.Name].CellColumns[0].MaximumWidth = 250;
chartSel.Legends[ySeries.Name].CellColumns.Add(new LegendCellColumn("", LegendCellColumnType.Text, ySeries.Name));
chartSel.Legends[ySeries.Name].CellColumns[1].Alignment = ContentAlignment.MiddleLeft;
chartSel.Legends[ySeries.Name].CellColumns[1].Margins = new System.Windows.Forms.DataVisualization.Charting.Margins(0, 0, 1, 1);
chartSel.Legends[ySeries.Name].CellColumns[1].MinimumWidth = 1500;
chartSel.Legends[ySeries.Name].CellColumns[1].MaximumWidth = 1500;
It's probably not the most efficient way to do it, but it works. Technically, the legend symbol and text are still centered in the object, but because I'm forcing the widths of the two columns it has the appearance of being left-justified.
Hopefully, this may help another newbie like me avoid days of consternation.
My understanding is that Legend alignment relates to the Docking property, not really how the text is aligned within the legend. So setting Alignment to Near means positioning the legend box near the Docking direction.
It is quite hard to explain this textually. The MS Chart Samples have a subsection named Chart features -> Legends -> Style and Auto Positioning which will help you play with those two properties and understand how they are meant to work.
For inner legend alignment, you may need to use Legend.CustomItems and define LegendCell individually.
chart.Legends["Default"].CustomItems.Clear();
chart.Legends["Default"].CustomItems.Add(new LegendItem("LegendItem", Color.Red, ""));
chart.Legends["Default"].CustomItems[0].Cells.Add(new LegendCell(LegendCellType.Text, "My text", ContentAlignment.MiddleLeft));
This is described inside the Chart features -> Legends -> Legend Cells section of the samples.
While continuing to try to figure this out I stumbled on this tidbit of info from the following MSDN library page:
http://msdn.microsoft.com/en-us/library/dd456711(v=vs.100).aspx
"NOTE: You cannot adjust the individual legend items and cells in the Chart.Legends collection. To adjust them, use custom legend items."
So, back to the CustomItem route. I've got this code gleaned from several sources (including you, Dominique, thanks):
chartSel.Legends.Add(ySeries.Name);
chartSel.Series[ySeries.Name].IsVisibleInLegend = false;
chartSel.Legends[ySeries.Name].CustomItems.Clear();
LegendItem li = new LegendItem();
li.ImageStyle = LegendImageStyle.Line;
li.Cells.Add(LegendCellType.SeriesSymbol, "", ContentAlignment.TopLeft);
li.Cells[0].BackColor = Color.CornflowerBlue; //color is only to see the cell bounds
li.Cells.Add(LegendCellType.Text, ySeries.Name, ContentAlignment.TopLeft);
li.Cells[1].BackColor = Color.Aquamarine; //color is only to see the cell bounds
chartSel.Legends[ySeries.Name].CustomItems.Add(li);
From what I can find it should work, but it doesn't. It results in a legend object with two cells; the first is empty and the second has left-justified text. I tried to post an image of it, but the system says I'm not yet worthy.
Why there is no line for the series symbol is also a mystery, but that's another problem to solve. The text justification issue is my main concern at the moment. It looks like the text within the cells is left-justified as desired, but the cells themselves are centered in the legend object; not what I wanted. I want those cells to be left-justified in the object too, so the first cell is against the left edge of the legend object.
Ideas?
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.
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.