DocumentBuilder position ambiguous after MoveToCell if cell empty


#1

after I execute: DocumentBuilder.MoveToCell(0, 0, 0, 0)

if the cell is empty, builder.CurrentNode returns null.

Shouldn't it return the cell's node?

What I'm trying to do is to get at the enclosing section with the following code:

Private Function getCurrentSection() As Section

Dim node As Node = _builder.CurrentNode

While node.NodeType <> NodeType.Section

node = node.ParentNode

End While

Return DirectCast(node, Section)

End Function

Is this an oversight or is there some design intent underlying this behavior?

My obvious workaround is to either place a space in the cell or to bookmark the cell and MoveToBookmark. Is there a better way?

Thanks.

-Charu Tevari
Software Architect
John Hancock Life Insurance

#2

This will be fixed in one of the future releases.

Meanwhile, putting spaces in the empty cells seems like a good workaround.


#3

The API for CurrentNode says when the current paragraph is empty or the cursor is positioned just before the end of the paragraph, CurrentNode returns null. This is the case with moving to an empty cell.

There is another property, DocumentBuilder.CurrentParagraph that gets the paragraph that is currently selected in this DocumentBuilder and you can use it when CurrentNode is null. If the paragraph is in a cell, then ParentNode of the paragraph will be the Cell you want.

At the moment there is no CurrentCell property, but I guess I could add a few more CurrentXXX properties if really needed.


#4

Please do.


#5

You can proceed even without waiting for these new properties.

CurrentNode points to an inline element or null. It can be Run, BookmarkStart, FieldStart etc.

CurrentParagraph points to the current paragraph, it is never null.

if (CurrentParagraph.ParentNode is Cell) then the parent node is a cell.

CurrentParagraph.ParentSection, CurrentParagraph.ParentStory are also available.


#6

Thanks Roman.

So my getCurrentSection() method would work if I modfy the first line of the method thus:

Dim node As Node = _builder.Currentparagraph '//vs. CurrentNode

Then I can iterate up the node.parent chain until I find the enclosing current Section [or Table, or Row, etc] ?


#7

Yes.

If you work with the Paragraph class, there is a shorcut to get the parent section Paragraph.ParentSection.

Also see the GetAncestor method, you can use GetAncestor(typeof(Table)) or whatever. It will do the loop through parents for you.