blindi

If I use TransformDocument(..) in a VSTO2005 Word-solution, and the insertion mark is currently in a XML-Node with an attached ContextLeave-Eventhandler, the event won't fire, but after the transformation the insertion mark is outside of the node.

I moved the insertion mark programatically out of the node with Application.Selection.GoTo(..) which worked, but also doesn't fired the event. Is there a way to force the event


Re: Visual Studio Tools for Office Force ContextLeave Event

Cindy Meister

Impossible to say without knowing the details of the transformation, but my guess would be that the transformation is actually destroying the existing nodes, and thus unlinking the event...




Re: Visual Studio Tools for Office Force ContextLeave Event

blindi

Thank you for your answer Cindy. I was on the wrong path, it's not a problem of TransformDocument, it's because I'm working with temporary documents which are closed and opened again. But the question is the same: How can I force the ContextLeave-Event




Re: Visual Studio Tools for Office Force ContextLeave Event

Cindy Meister

Unless you can supply more information about your process, it's not possible to attempt an answer. Since ContextLeave is only available on VSTO-controls - and not on "plain" XML nodes - the event can only execute on such nodes. If you're creating documents on-the-fly and aren't generating VSTO controls, then the event can't fire. But it's not clear from your questions exactly what you're doing...




Re: Visual Studio Tools for Office Force ContextLeave Event

blindi

I'm sorry for the inaccurate description. Here are some more details: It's a VSTO2005 Word template solution created with an existing Word 2003 template. Attached to the template is an extensive XML Schema, all the nodes, even the optional ones, are used once in the template.

The Schema was already used with several documents which where using the pre-VSTO way, implementing ISmartDocument. The new VSTO2005 solution will also be attached to this documents, replacing the old solution. The documents contain content for our E-Learning software, the VSTO2005 solution transforms the content to the necessary XML files.

Now I have this template within the solution and some (unfortunately not all and I really don't know why) nodes are available as VSTO-controls. For some of this nodes, available as VSTO-Controls, I wrote a ContextLeave-Handler, to replace some content somewhere with the content of the actually left node. This works fine, also in the old documents (thanks to an older thread "Handling optional XML-Nodes").

The problem is, that in some cases, for example when the document is closed programmatically, the node isn't really left and the handler will not be called. In this case I would call the handler before closing the document. I tried to call Application.Selection.GoTo(<Somewhere, 1. Letter>), but this doesn't fires the event. So, this is my question, how can I force the ContextLeave-event programatically My second question is why are not all nodes created as VSTO-controls when I create a new solution with a new template I can post the document and the nested Schema-files if necessary (but not the public forum).

Thanks, Oliver




Re: Visual Studio Tools for Office Force ContextLeave Event

Cindy Meister

Hi Oliver

If I create a BeforeClose event handler for the document, then change the selected node in there, it works for me. For example:

void ThisDocument_BeforeClose(object sender, System.ComponentModel.CancelEventArgs e)
{
Word.Range rng = ThisApplication.Selection.Range;
Word.XMLNode nd = rng.XMLParentNode;
nd.NextSibling.Range.Select();
}






Re: Visual Studio Tools for Office Force ContextLeave Event

blindi

Thank you very much Cindy, this works. Earlier I tried Application.Selection.GoTo which doesn't fires the event. For the second problem I mentioned, that not all nodes of the Schema are available as VSTO-Controls, I made a new thread.