none
Word 2007 VSTO - Error on locked content controls RRS feed

  • General discussion

  • using Word 2007, VSTO 3.0,  VS 2008 / .net 3.5

    Just in the last few weeks, I've noticed that any 'locked' plaintext content controls in my document level VSTO apps have produced errors (Word crashes) when the user clicks on them.  It also occurs when I set a group content control and lock it.... 

    If I unlock the content of the content control,  no errors - I've been using the same code for the last couple of years with no errors - has something been updated that is causing this problem? 

    I really would like to keep the content controls locked so I can force to user to input the text into a form... I'm doing this so I can populate various combo boxes with data from SQL tables, validate data, etc.


    Jo Crews

    Wednesday, December 12, 2012 5:53 PM

All replies

  • As a follow up - I had a very similiar question a few days ago ---but I was using code on the content control events -

    there is no code attached to any of the content controls in this document level customization... my solution was not to lock the content control until I had exited the content control - I did it in code after the event fired --   Now it doesn't matter - if its a group control or a plaintext content control, an error occurs upon the user clicking on the control...


    Jo Crews

    Wednesday, December 12, 2012 7:15 PM
  • Hi Jo,

    Thanks for posting in the MSDN Forum.

    Would you please show me some code for further research. I need reproduce you issue via your scenario.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, December 13, 2012 2:38 AM
    Moderator
  • Hi Tom - I am including the block of code that I use to lock the content controls (I have created a separate library of word methods that is used by several document-level and add-ins.  I then call these methods from the customization passing the necessary parameters.)

    The first block of code locks all plaintextcontrols and is called after the document is retrieved by the user:

    public static bool LockAllPlainText(Word.Application wordApp, Word.Document wordDoc, bool locked) { try { Word.ContentControls docControls = wordDoc.ContentControls; foreach (Word.ContentControl item in docControls) { if (item.Type == Word.WdContentControlType.wdContentControlText) { item.LockContentControl = locked; item.LockContents = locked; } } return true; } catch (Exception ex) { Utilities.Notification.LogErrors(ex, "wordMethods", "clsContentControls|LockAllPlainText; " + ex.Message); return false; } }

    The second block of code locks the top portion of the document based on passed bookmark paramters:

            public static bool AddGroup(Word.Application wordApp, Word.Document wordDoc, Word.Range myRange)
            {
                try
                {
                    object objRange = myRange;
                    DeleteGroup(wordApp, wordDoc);
                    myRange.Select();
    
                    Word.ContentControls docControls = wordDoc.ContentControls;
                    Word.ContentControl grpCC;
                    grpCC = docControls.Add(Word.WdContentControlType.wdContentControlGroup, ref objRange);
                    grpCC.LockContentControl = true;
    
                    Word.Range ContentRange = grpCC.Range;
                    ContentRange.Select();
    
                    object directionEnd = Word.WdCollapseDirection.wdCollapseEnd;
                    ContentRange.Collapse(ref directionEnd);
    
                    MoveFrom(wordApp, ContentRange, 1);
                    return true;
                }
                catch (Exception ex)
                {
                    Utilities.Notification.LogErrors(ex, "wordMethods", wordApp.Name + "; clsContentControls|AddGroup; " + ex.Message);
                    return false;
                }
            }
            //-------------------------------------------------------------------
    


    Jo Crews

    Thursday, December 13, 2012 3:49 PM
  • Hi Jo,

    Would you please tell me which method will execute first? AddGroup or LockAll PllaintText?

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, December 18, 2012 6:15 AM
    Moderator
  • Hi Tom, sorry I haven't replied sooner.  Finally decided to re-build my pc - this took care of the problem... don't know what was corrupted in the Office suite.... I had repaired it, re-installed it, etc.

    Anyway once the test pc was rebuilt - I no longer experienced any problems with the content controls.  Thanks for your help!


    Jo Crews

    Wednesday, December 19, 2012 3:22 PM