none
PlainTextContentControl: trying to set multiple line of text in code RRS feed

  • Question

  • Hi, i'm using a PlainTextContentControl. i'm trying to set the .Text property w/multiple lines of text, but only the first line is displayed INSIDE the content control.  the remaining lines are outside the content control.

    What am i doing wrong?

    Tuesday, March 8, 2011 6:57 PM

Answers

  • Bessie, i figured it out.

    i need to use "\v" instead of "\r" or "\n".

     

    i found this out by settign a debug watch and saw that in the code.

     

    tahnks for you help regardless.

    • Marked as answer by John Ireland Wednesday, March 9, 2011 3:52 PM
    Wednesday, March 9, 2011 3:52 PM

All replies

  • Hello John,

    Thanks for posting. For a general way, we could try to record a macro for these action in UI. By pressing Alt+F11, we could get the basic syntax from VBA code which indicates the methods and properties are used. VBA code like this,

    Sub Macro5()
        Selection.Range.ContentControls.Add (wdContentControlText)
        Selection.ParentContentControl.MultiLine = True
    End Sub

    If the information above does not help you, would you mind sharing the code about this issue with us? So I could use it on my side to reproduce this issue for further research. Have a nice day.


    Bessie Zhao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, March 9, 2011 3:52 AM
  • in design time, the Microsoft.Office.Tools.Word.PlainTextContentControl's properties are set as such:

    name of the ptc is:  ptcAttachments.

    LockContentControl = true

    MultiLine = true.

    i have a custom Document Actions Pane that has a datagrid which has 2 values:  Tab and Attachment.  both are text fields.  once i click a button, the code gets the value of Tab and attachment, for each row in the datagrid.  For each row, it concats the two together.  i then add "\r" at the end of the string for each row.  I use a string builder object to perisist these "rows".

    Then i set the ptcAttachments.Text property to the stringBuilder.ToString() method:

    StringBuilder sb = new StringBuilder();
    foreach(DataGridViewRow row in this.dgAttachments.Rows)

    {
         if (row.Cells["Attachment"].Value != null)
         {
              string tab = string.Concat("TAB ", row.Cells["Tab"].Value as string, ": ", row.Cell["Attachment"].Value as string, "\r");
                       

             sb.AppendLine(tab);

         }
    }

    Globals.ThisDocument.ptcAttachments.Text = sb.ToString();

     

    What happens is the first line of text is within the ptcAttachments control, and all others lines are underneath and outside of the content control.

     

    i've also tried using the ptcAttachments.Range.Text, but that does the same thing.

     

    Wednesday, March 9, 2011 1:13 PM
  • Bessie, i figured it out.

    i need to use "\v" instead of "\r" or "\n".

     

    i found this out by settign a debug watch and saw that in the code.

     

    tahnks for you help regardless.

    • Marked as answer by John Ireland Wednesday, March 9, 2011 3:52 PM
    Wednesday, March 9, 2011 3:52 PM
  • Hello again John,

    Glad to know that you have find a workaround for this issue. Also thanks very much for coming back to share it with us. It will probably help others facing the same issue in this forum. Have a nice day.


    Bessie Zhao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, March 10, 2011 10:03 AM