This is a migrated thread and some comments may be shown as answers.

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

3 Answers 80 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Dave
Top achievements
Rank 1
Dave asked on 30 Apr 2011, 12:48 AM
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?

 

3 Answers, 1 is accepted

Sort by
0
Iva Toteva
Telerik team
answered on 05 May 2011, 05:00 PM
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
0
Dave
Top achievements
Rank 1
answered on 19 May 2011, 08:36 AM
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();


0
Boby
Telerik team
answered on 24 May 2011, 03:57 PM
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
Tags
RichTextBox
Asked by
Dave
Top achievements
Rank 1
Answers by
Iva Toteva
Telerik team
Dave
Top achievements
Rank 1
Boby
Telerik team
Share this question
or