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.
Related
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
I'm dynamically creating a PowerPoint using C# and I need to create a table with variable rows and columns (depends on the data which I'm processing.) The following code creates the table.
PowerPoint.Application pptObj = new PowerPoint.Application();
PowerPoint.Presentations presObj = pptObj.Presentation;
PowerPoint.Presentation pObj = presObj.Add(MsoTriState.msoTrue);
PowerPoint.Slides objSlides;
PowerPoint.Slide objSlide;
PowerPoint.Shapes shapes;
float pHeight = pObj.PageSetup.SlideHeight;
float pWidth = pObj.PageSetup.SlideWidth;
objSlide = objSlides.Add(1,PowerPoint.PpSlideLayout.ppLayoutTitleOnly);
shapes = objSlide.shapes;
shapes.AddTable(16,7,20,100,pWidth - 40,pHeight - 150);
I might have left other code details. The problem is the table not enclosed inside the slide. It goes out of it.
I'm not able to rescale the table. Is there any other I can resize the table and fit it inside the slide irrespective of the number of rows and columns?
Tables grow to accommodate the amount of text they hold; individual rows cannot be made to shrink to a height below what's needed to hold their text at the current font size + leading + margins and such.
So the answer to your problem is likely to be something like:
Create your table
Add all of the rows, columns and text you want to add to the table with the text in whatever maximum size you'd like.
THEN in a loop:
Reduce the text size and/or spacing and then the height of each row until the overall size of the table meets your needs.
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;
I'm trying to build a TableLayoutPanel on a WinForm and want it to behave exactly like a plain old HTML table.
One requirement is that this table needs to be built programmatically. This is what I have so far:
foreach (var RowLinq in ResultLinq)
{
RichTextBox RT = new RichTextBox();
RT.BorderStyle = BorderStyle.None;
RT.Text = RowLinq.Result.ResultName;
RT.Dock = DockStyle.Fill;
TableLayoutPanel.RowCount++;
TableLayoutPanel.RowStyles.Add(new RowStyle(System.Windows.Forms.SizeType.AutoSize));
TableLayoutPanel.Controls.Add(rt1, 0, tableLayoutPanel5.RowCount - 1);
}
So this builds a row for each row in my Linq result. This works pretty well except for one thing: the height doesn't adjust at all and is completely fixed. I need the height to grow and shrink depending on the height of the text inside each cell.
I need your help with this one big time, thanks Stack-o
Set its AutoSize property to True.
I have a DataGrid with some template columns that contain another DataGrid. My problem is that if some rows have a lot of content in them their height doesn't adjust so the whole content is visible, but rather it's cut off, giving the impression that the rows overlap. However, as soon as I add a new row to the grid or add a new row to the mini-grid inside one of the main grid's rows, the layout gets updated and the row heights are resized correctly.
So the problem is only when loading the grid the first time.
Is there a way to force the grid to size the rows heights to their content?
Thanks
I had some serious trouble with this (bug?) today, so I'll share what I tried and what almost worked... (And hope that someone knows an actual fix)
In my case the bug only appeared when there were 10 or more rows. Out of the rows, ten first rows would in some cases have too small height for the contents. (I first thought that the nine items were drawn on top of each other, which was stupid of me.) There are quite many columns, so there's a scrollbar. Clicking on the scrollbar resizes the heights to proper values.
Some things that in my experience do not work:
Changing virtualization settings had no effect.
InvalidateVisual() and InvalidateArrange() don't work. Tried both datagrid and its parent.
Changing the height of datagrid did not work (although I'm not quite happy with my tests here)
Forcing the datatemplates of the cells to a specific size did not have an effect.
Placing the datagrid inside a scrollviewer (so that the datagrid would have all the space it could ever need...) did not work.
However:
The one thing (I found) that the datagrid seems to respect is MinRowHeight-setting, so now I've got there a moronic value and I'm hoping that this won't cause problems later on when the datatemplates are modified.
I experienced the same bug with the DataGrid that comes with the .NET Framework 4.0.
Under certain circumstances (no horizontal scrollbar, window is bigger than a specific size, ...) the rows were not displayed correctly but placed on top of another (with a small offset), so just the last row was completely visible.
First I tried to perform a UI-action automatically after the rows are filled in the DataGrid, so the layout is updated. But then I found out, that you can just re-render the control using the dispatcher, which, in my case, fixed the bug eventually.
My whole code-change basically is this (right after filling the DataGrid):
Action emptyAction = delegate() { };
myDataGrid.Dispatcher.Invoke(DispatcherPriority.Render, emptyAction);
I'm not sure what is this, but you could try call InvalidateVisual(), some time later, when element is loaded. This forces complete new layout pass...
The DataGrid in my UserControl is doing the same thing. In this example, there are only 32 rows of data with five DataGridTemplateColumns consisting of an <Image> and four <TextBlock>s.
My control shows search results, if I rerun the same search it does not always do this. In addition, the cropping only occurs, roughly, on the first pageful of results. Rows further down are ok.
Using InvalidateVisual() does not help.
If anyone has any ideas on how to solve this or can indicate if this is a known issue with that control, I'd be interested in hearing about it.
In my case I just needed to add the first row before the loop adding extras.
I wanted 4 columns and n rows like this:
private void InitToList() {
Grid wp = new Grid();
wp.Margin = new Thickness(0);
wp.ColumnDefinitions.Add(new ColumnDefinition());
wp.ColumnDefinitions.Add(new ColumnDefinition());
wp.ColumnDefinitions.Add(new ColumnDefinition());
wp.ColumnDefinitions.Add(new ColumnDefinition());
wp.RowDefinitions.Add(new RowDefinition()); // adding this fixed the overlapping
int curCol = 0;
int curRow = 0;
foreach (string name in toIds) {
if (curCol >= wp.ColumnDefinitions.Count()) {
wp.RowDefinitions.Add(new RowDefinition());
curCol = 0;
curRow++;
}
CheckBox cb = new CheckBox();
cb.Name = String.Format("{0}Check", name.ToLower().Replace(" ", ""));
cb.IsChecked = false;
cb.Margin = new Thickness(5, 5, 5, 5);
cb.Content = name;
Grid.SetColumn(cb, curCol);
Grid.SetRow(cb, curRow);
wp.Children.Add(cb);
curCol++;
}