I think the problem will go away if you will not use the tools to data-bind your dataset to the bookmark, but would rather do the data-binding manually after you have already shown the ActionsPane in the ThisDocument_Startup method.
I am following your posts to this forum and I see you go through a lot of pain with this and no one so far gave you any explanation on what is going on. So I will try to help you understand what is really happening.
In Word it is possible to view the same document in multiple windows (just open a new document and choose either Split or New Window in the Window menu). However, Word does not allow displaying the Document Actions Task Pane when document is being viewed in several windows. Also notice that Document Actions Task Pane would only appear if there is a SmartDoc solution attached to the document. ActionsPane utilizes the Document Actions Task Pane and is built on top of the SmartDoc infrastructure. VSTO under the covers attaches a Microsoft ActionsPane SmartDocument solution to the document when ActionsPane.Control.Add(somecontrol) is called. This triggers Word's SmartDoc initialization logic. This logic checks whether document is currently opened in multiple winows and ,if it is, smart doc initialization fails. But you did not do anything that would have mulitple windows for this document, right? The reason for the failure is that there are few operations in Word (and modifying a text in the bookmark is one of those operations) that create some auxiliary windows that are intenrally linked to the Word document. Normally, those windows should not be exposed to the end-user, but the smart doc initialization incorrectly accounts this auxiliary windows for the real ones. This is a bug and as much as we wanted in VSTO to workaround this bug we could not have done it in all the situations. I would not list here all the possible scenarios that would lead to the creation of the auxiliary windows. It should suffice to say that we made Word aware of the problem and Office SP2 should contain a fix for this bug.
There is something in the user code you could do though to workaround this.
The solution is to force the initialization of the smart document solution in an earlier stage - before those auxiliary windows are created.
If you use the visual tools to databind cached datasets to a bookmark the text in the bookmark will be changed prior to ThisDocumen_Startup call and hence the auxiliary window will be created before you have any chance to force ActionsPane initialization. Hence, I suggest to do databinding to bookmarks manually in ThisDocument_Startup event (you can look at ThisDocument.designer.cs file to see the code the designer is generating and do similar stuff).
Now, there is one more scenario when this technique fails. And this is when you add SmartTags into the picture. This is because when SmartTags are used VSTO runtime will reload all the SmartTags objects (and its cousine SmartDocs objects) after ThisDocument_Startup completes. This causes the SmartDocs to be re-initialized after you have already created all the auxiliary windows. In this case the below workaround worked for me OK. I highlighted the tricky part. Here I am actually exposing some of the VSTO SmartTags implementation details that are not guaranteed to work in the final version VSTO 2005 - so use with caution.
Hope this helps.
Misha
using System;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.VisualStudio.Tools.Applications.Runtime;
using Word = Microsoft.Office.Interop.Word;
using Office = Microsoft.Office.Core;
using Microsoft.Office.Tools.Word;
using Microsoft.Office.Interop.SmartTag;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
namespace WordDocument8
{
public partial class ThisDocument
{
private void ThisDocument_Startup(object sender, System.EventArgs e)
{
SmartTag st = new SmartTag("moo#moo", "Moo");
st.Terms.Add("Foo");
st.Terms.Add("Bar");
st.Actions = new Action[] { new Action("Dummy action") };
this.VstoSmartTags.Add(st);
this.ActionsPane.Controls.Add(new Button());
this.ActionsPane.Controls.Add(new TextBox());
ISmartTagSite site = this.RuntimeCallback.GetService(typeof(ISmartTagSite)) as ISmartTagSite;
site.ResumeReload();
site.SuspendReload();
site.SuspendReload();
moo.Text = "GMMM";
}
private void ThisDocument_Shutdown(object sender, System.EventArgs e)
{
}
}
[
ComImport,
Guid("8b189642-3252-4214-b153-87fcdb178e75"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)
]
internal interface ISmartTagClient
{
string SmartTagType { get; }
string Caption { get; }
int ActionsCount { get; }
string GetActionCaption(int idx, string Text, ISmartTagProperties properties, [In, MarshalAs(UnmanagedType.IUnknown)] object range);
void OnRecognize(string Text, ISmartTagRecognizerSite site, ISmartTagTokenList tokens);
void OnExecute(int idx, string Text, ISmartTagProperties properties, [In, MarshalAs(UnmanagedType.IUnknown)] object range);
}
[
ComImport,
Guid("c84484f6-52d3-46c7-857c-2fef0564e989"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)
]
internal interface ISmartTagSite
{
void Add([In, MarshalAs(UnmanagedType.Interface)] ISmartTagClient smartTagClient);
void Remove([In, MarshalAs(UnmanagedType.Interface)] ISmartTagClient smartTagClient);
void RemoveAll();
void SuspendReload();
void ResumeReload();
}
}