PDFsharp & MigraDoc Foundation https://forum.pdfsharp.net/ |
|
KeepWith problem https://forum.pdfsharp.net/viewtopic.php?f=2&t=3743 |
Page 1 of 1 |
Author: | edwardkoks [ Wed Mar 14, 2018 9:07 pm ] |
Post subject: | KeepWith problem |
Hello, I'm creating an new report in C#. I have a table where two rows must be kept together. According to documentation, this can be done using row.KeepWith =2 ; However when I run my application, the rendereDocument Method results in an exception. Specific a keynotfoundexception (The given key was not present in the dictionary) at System.Collections.Generic.Dictionary`2.get_Item(TKey key) at MigraDoc.Rendering.TableRenderer.Format(Area area, FormatInfo previousFormatInfo) at MigraDoc.Rendering.TopDownFormatter.FormatOnAreas(XGraphics gfx, Boolean topLevel) at MigraDoc.Rendering.FormattedDocument.Format(XGraphics gfx) at MigraDoc.Rendering.DocumentRenderer.PrepareDocument() at MigraDoc.Rendering.PdfDocumentRenderer.PrepareDocumentRenderer(Boolean prepareCompletely) at MigraDoc.Rendering.PdfDocumentRenderer.PrepareRenderPages() at MigraDoc.Rendering.PdfDocumentRenderer.RenderDocument() at BikeBillLibrary.Helpers.DocumentHelper.CreatePDF(DocumentModel doc) in K:\\Data\\Dropbox\\netProjects\\BikeBillNew\\BikeBillLibrary\\Helpers\\DocumentHelper.cs:line 142 at BikeBillLibrary.ViewModels.FactuurKlantViewModel.MaakFactuur() in K:\\Data\\Dropbox\\netProjects\\BikeBillNew\\BikeBillLibrary\\ViewModels\\FactuurKlantViewModel.cs:line 362 at BikeBillUI.Views.FactuurKlant.Factuur_Executed(Object sender, ExecutedRoutedEventArgs e) in K:\\Data\\Dropbox\\netProjects\\BikeBillNew\\BikeBillUI\\Views\\FactuurKlant.xaml.cs:line 82" When I comment 'row.KeepWith=2;' out, the RenderDocument executes fine! I've installed PDFSharp-MigraDoc-wpf from buget, version 1.50.4790-beta5a |
Author: | edwardkoks [ Wed Mar 14, 2018 9:24 pm ] |
Post subject: | Re: KeepWith problem |
The problem is probably that I have an odd number of rows in my table. My table consist of a header row followed by items , in pair of two rows. So I want to keep the pair of two rows together on a page. Therefore I've set my KeepWith=2 on the first row AFTER the header row. However, since this is in a loop, the KeepWith is being set on each new pair of two rows... Code: table = section.AddTable(); table.Rows.LeftIndent = 0; var column = table.AddColumn("13cm"); column = table.AddColumn("1.5cm"); column = table.AddColumn("2.5cm"); column = table.AddColumn("2.5cm"); // Create the header of the table. var row = table.AddRow(); row.HeadingFormat = true; // repeat on each page row.Borders.Bottom.Width = 0.25; row.Cells[0].AddParagraph("Artikelomschrijving"); row.Cells[1].AddParagraph("Aantal"); row.Cells[2].AddParagraph("Artikelprijs"); row.Cells[3].AddParagraph("Arbeidsloon"); foreach (DocumentDetailModel item in _doc.DocumentDetails) { // first row of 2 row = table.AddRow(); row.KeepWith = 2; row.Cells[0].AddParagraph(item.Artikelomschrijving); row.Cells[1].AddParagraph(item.Aantal.ToString()); row.Cells[2].AddParagraph($"{(item.Artikelprijs * item.Aantal).ToString("0.00")} €"); row.Cells[3].AddParagraph($"{item.Arbeidsloon.ToString("0.00")} €"); // second row row = table.AddRow(); if (item.Artikelomschrijvingdetail!=null && item.Artikelomschrijvingdetail.Trim()!=String.Empty) { row.Cells[0].AddParagraph(item.Artikelomschrijvingdetail); } } |
Author: | TH-Soft [ Wed Mar 14, 2018 10:40 pm ] |
Post subject: | Re: KeepWith problem |
Hi! edwardkoks wrote: According to documentation, this can be done using row.KeepWith =2 ; Where is that documentation?To keep two rows together, you have to write "KeepWith = 1". You count the rows you attach to the current row. |
Page 1 of 1 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |