0

I am building a table in MigraDoc. I have found a way to put a Table into a Table.Row.Cell with the help of a TextFrame. Unfortunately the Row.Cell does not grow when adding new entries into the TextFrame. So at a certain point the inner table overlaps into the rows beneath.

Here is my Code:

this.Table = this.MigraDokument.AddSection().addTable();
Row row = this.Table.AddRow();
TextFrame Frame = row.Cells[0].AddTextFrame();

Table k_table = Frame.AddTable();
// adding rows with 
// Row row2 = k_table.AddRow();

How can I tell the Row.Cell to grow with every entry that I put into the inner Table?

Edit: My problem was not that I could not add a nested table, like in [MigraDoc - imbricated / nested tables?. Although the answer from the link helped me. This question deals with the topic that TextFrames might be an inappropriate way to nest tables in tables because the Cell does not scale with the nested table.

Community
  • 1
  • 1
Mong Zhu
  • 23,309
  • 10
  • 44
  • 76
  • Possible duplicate of [MigraDoc - imbricated / nested tables?](http://stackoverflow.com/questions/36303719/migradoc-imbricated-nested-tables) – I liked the old Stack Overflow Apr 25 '16 at 14:39
  • It is a possible dublicate in a way, although my problem itself is a little different from that in the Link. But the solution/hack from the Link helped. See my Answer. Thanks PDFsharp Team – Mong Zhu Apr 26 '16 at 13:52
  • Not the same question, but the same problem - and the same solution works for both questions. Do we need them both if they are just a little different? – I liked the old Stack Overflow Apr 26 '16 at 14:28
  • The same solution solved two different problems. If you think that my post is superfluous I can remove it (no hard feelings), but in my point of view it is a different problem. I did not find the other post when researching my problem neither in StackOverflow nor Google. – Mong Zhu Apr 26 '16 at 15:28

1 Answers1

1

The undocumented feature from [MigraDoc - imbricated / nested tables? was the Answer: Now the code looks this way and it works fine.

this.Table = this.MigraDokument.AddSection().addTable();
Row row = this.Table.AddRow();
// Here I grab the cell that I want to populate later
Cell dataCell = row.Cells[0];

// Than I build the table with alle the necessary Information in it
Table k_table = new Table();
// adding columns and rows with 
k_table.AddColumn();
k_table.AddColumn();
Row row = k_table.AddRow();
// and populate with data
row.Cells[0].AddParagraph("Stuff 1");
row.Cells[1].AddParagraph("Stuff 2");

// The final trick is to add it in the end to the `Elements`
// property of the cell
dataCell.Elements.add(k_table);

The last step has the effect that the Table-Cell has grown to the extend, that the nested table affords! No merging with extra rows beneath was necessary. This approach seems to be more flexible than using a TextFrame as I tried in my question.

Community
  • 1
  • 1
Mong Zhu
  • 23,309
  • 10
  • 44
  • 76