none
Events for a plainTextContentControl in a table RRS feed

  • Question

  • In the Word document I am developing VSTO code for, we have a table with three columns.  In the left-most column there is a plainTextContentControl (PTCC).  I have successfully added events for this PTCC.  For example, when I run the project and click into the PTCC and then tab away, it fires off the exiting event.

    The table (which contains the PTCC) has to allow the user to add more rows during runtime.  Unfortunately, when I add additional rows at runtime, I can't get the PTCC events to run except for the first one that is there.

    Does anyone have a suggestion about how to make sure that if the user adds rows at runtime the events for the new PTCC can be triggered (just like the initial row)?

    Thanks in advance.

    Monday, September 21, 2015 8:12 PM

Answers

  • ​>>>Does anyone have a suggestion about how to make sure that if the user adds rows at runtime the events for the new PTCC can be triggered (just like the initial row)?

    According to your description, I think you could use Repeating Section Content Control and ContentControlOnExit event, you could refer to like below:

    1. Use Repeating Section Content Control

    1.JPG 

    2. Design Table

    1-1.JPG 

    3. Choose PlaintTextContentControl

    1-2.JPG 

    4. Set PlaintTextContentControl‘s "Tag" Property to "Control1"

    1-3.JPG 

    5. Add ContentControlOnExit Event

    private void ThisDocument_Startup(object sender, System.EventArgs e)
    
    {
    
       this.ContentControlOnExit += ThisDocument_ContentControlOnExit;
    
    }
    
    
    private void ThisDocument_ContentControlOnExit(Word.ContentControl ContentControl, ref bool Cancel)
    
    {
    
        if (ContentControl.Tag == "Control1")
    
        {
    
            MessageBox.Show("Exiting");
    
        }
    
        else
    
        {
    
            Cancel = true;
    
        }          
    
    }
    


    Thursday, September 24, 2015 9:52 AM