This project has moved and is read-only. For the latest updates, please go here.

Keeping table rows together

Jul 12, 2012 at 1:20 PM
Edited Jul 12, 2012 at 3:12 PM

Hi.

 

Is there any way to make sure the rows of a table stay together?

I need to make sure that the entire table is moved to the next page if a pagebreak happens.

I can't see anyway of finding an objects current page or a setting to keep objects together.

 

Technically I can see a way. I hacked this in going through all the rows, except the last one, and getting the Xml property and then going through all it's descendants and adding a "keepNext" node to any descendant with LocalName = "pPr".

This works but is a nasty hack so I am hoping there is a better way.

  Thanks, Vincent

Jun 11, 2014 at 11:53 AM
In my project I always want the tables to stay together and not split across pages, so I used vfinn's suggestion above to change the function CreateTableCell() in HelperFunctions.cs to always add the keepNext node to any new Cell:
        internal static XElement CreateTableCell()
        {
            return new XElement
                    (
                        XName.Get("tc", DocX.w.NamespaceName),
                            new XElement(XName.Get("tcPr", DocX.w.NamespaceName),
                            new XElement(XName.Get("tcW", DocX.w.NamespaceName),
                                    new XAttribute(XName.Get("w", DocX.w.NamespaceName), "2310"),
                                    new XAttribute(XName.Get("type", DocX.w.NamespaceName), "dxa"))),
                            new XElement(XName.Get("p", DocX.w.NamespaceName),
                                new XElement(XName.Get("pPr", DocX.w.NamespaceName),
                                    new XElement(XName.Get("keepNext", DocX.w.NamespaceName))))
                    );
        }