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
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;
}
}
Iva
the Telerik team

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();
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