none
Checking the value of a PlainTextContentControl RRS feed

  • Question

  • Hello,

    I have created a Word project in Visual Studio 2012.  My goal is to have the value of a PlainTextControl conditionally set the appropriate checkbox else on the form.  (For example, if the user puts "1" there, the first checkbox gets set, etc.)

    I have created Exiting, Entering and ContentUpdating methods in the "cs" file.  When I start the project, I enter a value in the PlainTextControl in question.  In all three methods, I wish to inspect the value that I've set.  However, I am not seeing what I entered.  For example, if I put a "7" in the PlainTextControl, I am seeing this:

              plainTextContentControl25.Text = "[]"

    I have tried to access the Range property, the Cells property and the Characters property.  I have yet to see a "7" as the property of the control's text anywhere.

    How do I inspect the text the user entered into a PlainTextContentControl while in one of its methods?

    Wednesday, September 16, 2015 5:25 PM

Answers

  • OK, I just realized what the problem is.  Thanks to my increasingly bad vision, I used the wrong name of the control.  Once I realized what the correct name was, I see the value that I expect in the Text property.

    Thanks,

    • Marked as answer by ScottMDGov Thursday, September 17, 2015 5:38 PM
    Thursday, September 17, 2015 5:38 PM

All replies

  • >>>How do I inspect the text the user entered into a PlainTextContentControl while in one of its methods?

    If I didn't misunderstand, you could refer to like below:

    private void plainTextContentControl_Entering(object sender, ContentControlEnteringEventArgs e)
    {
    
         Microsoft.Office.Tools.Word.PlainTextContentControl control=sender as Microsoft.Office.Tools.Word.PlainTextContentControl;
    
         //control.Text 
    
    }
    

    This method's first parameter is of type Object and refers to the instance that raises the event. If plainTextContentControl25 raises the event, object sender parameter refers to plainTextContentControl25.

    Thursday, September 17, 2015 9:27 AM
  • Hi David_JunFeng, thanks for the reply.  Unfortunately, the code does not work differently than my previous example.

    I start the project and set the value of a PlainTextContentControl to 7.  My intention is to check for this value, i.e.,:

    privatevoidplainTextContentControl125_Entering(objectsender, ContentControlEnteringEventArgse) {

    if (plainTextContentControl25.Text == "1") ...     

    ...but setting a breakpoint and adding a watch confirms that:
    plainTextContentControl25.Text = "[]"

    This does not equal "7".  If I use the code you provide, I still see this:
    control.Text = "[]".

    I am trying to see the Text property show a "7", so that I can use an "if" statement only when the user has indicated 7.

    I don't know why I keep seeing "[]" when I put "7" or any other number in the PlainTextContentControl.  I have also been looking at all the properties for the control (there must be a thousand) trying to find the "7", but haven't seen it yet.

    Thanks,


    • Edited by ScottMDGov Thursday, September 17, 2015 12:36 PM
    Thursday, September 17, 2015 12:33 PM
  • OK, I just realized what the problem is.  Thanks to my increasingly bad vision, I used the wrong name of the control.  Once I realized what the correct name was, I see the value that I expect in the Text property.

    Thanks,

    • Marked as answer by ScottMDGov Thursday, September 17, 2015 5:38 PM
    Thursday, September 17, 2015 5:38 PM