Tab key not working in tables in a Word Document protected for forms using VSTO
-
martes, 07 de noviembre de 2006 20:02I have come across a problem when programming VSTO. If I have a Word document that is protected for forms by section where one of my unprotected sections contains a table. I am having difficulty using the "tab" key within the table when clicked (tab won't move to the next cell or create a new row from the last cell).
This problem does not occur when programmed directly in VBA.
C#/VSTO:
object oMissing = System.Reflection.Missing.Value;
object oContinuous = Word.WdBreakType.wdSectionBreakContinuous;
private void ThisDocument_Startup(object sender, System.EventArgs e)
{
ThisApplication.Selection.InsertBreak(ref oContinuous);
this.Tables.Add(ThisApplication.Selection.Range, 2, 5, ref oMissing, ref oMissing);
Sections[1].ProtectedForForms = true;
Sections[2].ProtectedForForms = false;
Protect(Microsoft.Office.Interop.Word.WdProtectionType.wdAllowOnlyFormFields, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
}
VBA:Selection.InsertBreak Type:=wdSectionBreakContinuous
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=2, NumColumns:= _
5, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
wdAutoFitFixed
ActiveDocument.Sections(1).ProtectedForForms = True
ActiveDocument.Sections(2).ProtectedForForms = False
ActiveDocument.Protect (wdAllowOnlyFormFields)
Todas las respuestas
-
miércoles, 15 de noviembre de 2006 16:42Moderador
Hi Bill
Interesting. I concur, and the problem appears to be not only in tables, but in the entire unprotected section. When I press TAB, the focus jumps to form fields in the protected section. Ctrl+Tab (which should insert a TAB character into a Table cell) is also affected. I see the same behavior if I create the unprotected section manually in a VSTO document.
Conclusion: this is a "bug" in how VSTO is constructing the document customization.
(Aside: I'm surprised that C# allows you to use Protect without this.InnerObject. in front of it. C# is usually so finicky about correct qualification...)
The only workaround I can find is to assign a shortcut key combination in the document (opened in Word, not in the VSTO designer) to the command NextCell.
Posted public "Feedback" here:
https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=238241
-
lunes, 23 de abril de 2007 18:27
Recently I recieved an e-mail from Microsoft support saying that they closed the issue I opened as not reproducible.
Clearly, the problem is reproducible.
Anyway, what I ended up doing was rolling my own protection mechanism by writing some complicated logic in the handler for the ChangeSelection event. This allowed me to turn off Protection all together. Without Forms protection I can successfully navigate my tables with the TAB key.
-
martes, 24 de abril de 2007 13:04Moderador
Hi Bill
As I recall, the tracking on the problem was for the next version of VSTO. Apparently they aren't going to look at changing anything for existing versions...
Glad you found a viable approach (even though it sounds like a horrendous amount of work) and took a moment to update this thread :-)
-
viernes, 25 de mayo de 2012 20:11
I am not using VSTO but have the exact same issue. It is reproducible. Seems when I add an activeX control (radio button) to the protected section, then the TAB key acts as listed above and will not tab between cells in an unprotected table or create a new empty row etc.
Not sure if anyone is still looking at this thread, I may post a new one to resurrect this topic.

