Comment's As a List, the contains and selected text

4 posts, 0 answers
  1. Dave
    Dave avatar
    32 posts
    Member since:
    Feb 2008

    Posted 29 Apr 2011 Link to this post

    During this workflow -  User selects by dragging the cursor over two words in a document.  Selects the 'Add Comment' from the 'Review' Tab.   Repeats this processing three times. Saves the document.  
    How can we make a List of the Comments.  Read the contains of those 'Comments' and determine which 'two words' were selected for each Comment?

     
  2. Iva Toteva
    Admin
    Iva Toteva avatar
    1319 posts

    Posted 05 May 2011 Link to this post

    Hello Dave,

    Thank you for your question. Please see below how you can perform each of the two requests - get the text in the big document, which is being commented on and get the text of the comments themselves:

    private IEnumerable<string> GetAllCommentBodies()
    {
        TxtFormatProvider txtFormatProvider = new TxtFormatProvider(); 
        foreach (CommentRangeStart comment in this.radRichTextBox.Document.EnumerateChildrenOfType<CommentRangeStart>())
        {
            CommentRangeEnd commentEnd = comment.End as CommentRangeEnd;
            RadDocument commentBody = commentEnd.Comment.Body;
            string plainText = txtFormatProvider.Export(commentBody);
            yield return plainText;
        }          
    }
      
    private IEnumerable<string> GetAllTextBetweenCommentRangeStartAndEnd()
    {
        TxtFormatProvider txtFormatProvider = new TxtFormatProvider();
        this.radRichTextBox.Document.Selection.Clear();
        foreach (CommentRangeStart comment in this.radRichTextBox.Document.EnumerateChildrenOfType<CommentRangeStart>())
        {
            this.radRichTextBox.Document.Selection.SelectAnnotationRange(comment);
            RadDocument document = this.radRichTextBox.Document.Selection.CreateDocumentFromSelection();
            this.radRichTextBox.Document.Selection.Clear();
            string plainText = txtFormatProvider.Export(document);
            yield return plainText;
        }
    }
    The code in the snippet uses TxtFormatProvider, which will retrieve the documents' content stripped of formatting. You can choose any of the format providers, depending on the processing you will be performing afterwards. Best wishes,
    Iva
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Dave
    Dave avatar
    32 posts
    Member since:
    Feb 2008

    Posted 19 May 2011 Link to this post

    Thanks for the reply and examples.

    I'm attempting to understand how to combine the 'selected text' plus 'comments' and display those results in a datagrid as seen in the code below.  My method is too generic to succeed.    Is there another method to get the selection?  Any suggestions are appreciated. 

    private IEnumerable<List<string[]>> SelectedTextAndCommentBody()
            {
                List<string[]> list = new List<string[]>(2); // List constructor

                this.cuftEditor.Document.Selection.Clear();
                IEnumerable<CommentRangeStart> comments = this.cuftEditor.Document.EnumerateChildrenOfType<CommentRangeStart>();
               
                foreach (CommentRangeStart comment in comments)
                {
                      TxtFormatProvider cuftFormatProvider = new TxtFormatProvider();

                    CommentRangeEnd commentEnd = comment.End as CommentRangeEnd;
                    RadDocument commentBody = commentEnd.Comment.Body;               
                    string plainText = myFormatProvider.Export(commentBody);

                    this.myEditor.Document.Selection.SelectAnnotationRange(comment);
                    RadDocument document = this.myEditor.Document.Selection.CreateDocumentFromSelection();
                    this.myEditor.Document.Selection.Clear();
                   
                    string plainText2 = myFormatProvider.Export(document);

                    string csv = plainText + "," + plainText2;

                    string[] parts = csv.Split(',');
                  
                    list.Add(parts);
          
                    yield return list;
                }

    listOfActionableItems.ItemsSource = SelectedTextAndCommentBody();


  4. Boby
    Admin
    Boby avatar
    763 posts

    Posted 24 May 2011 Link to this post

    Hi Dave,

    I am not sure if I understand what are you trying to achieve, but it looks like a question of proper data binding of data grid to list of data objects. SelectedTextAndCommentBody can, for example, return a list of custom class (or event Tuple) containing the information you need – namely comment body and comment range text – then you can bind the data grid columns to the properties of the custom class.
    Please get back to us if you need further assistance.

    Greetings,
    Boby
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top