tags:

views:

296

answers:

2

I am developing a Word 2007 document template with VSTO. The document has several RichTextContentControls and there is a visible ActionsPane with a treeview control where the nodes of the treeview are the names of the RichTextContentControls.

Users can re-order nodes by dragging/dropping nodes to new locations in the treeview. As nodes are dropped, the corresponding RichTextContentControls should be re-ordered according the new node locations.

I am able to find the Range of the control that the new control is supposed to be moved above of. Now I only need to find a way to simply...move the control to this new location.

How can I move a control above/below a range?

+1  A: 

Did you ever find an answer to this question? I have to do the same thing.

+3  A: 

I did this with a bookmark inside of a RichTextControl to just move it above/below another one from two buttons in the actions pane. Like this for moving up where "bm" below equals the selected bookmark:

Dim pageBookmark As Microsoft.Office.Tools.Word.Bookmark
pageBookmark = Globals.ThisDocument.Controls.Item(bm)
pageBookmark.Range.Relocate(Direction:=Word.WdRelocate.wdRelocateUp)

For a tree view, it would be more complex, but I could see that you would want all your richtext controls to be indexed (maybe use the "tag" property) and then as you move them in your tree view, use the index to add/subtract from other indexes and then use the "Relocate" method in a loop that many times to get it to it's new location. Then you can loop and recreate the index. Application.ScreenUpdating = False at the start of the loops and set it back to = True at the end of the loop would stop the flicker as well.

Otaku