Hi,
Based on a Selection, I would like to add a comment.
I was wondering how i would do this within the code.
So i have my selection:
Based on a Selection, I would like to add a comment.
I was wondering how i would do this within the code.
So i have my selection:
this.editor.Document.Selection // I would like to add my comment for this selection. An example for doing this would be great. Thanks
5 Answers, 1 is accepted
0
![](/forums/images/avatarimages/default.gif)
Marcel
Top achievements
Rank 1
answered on 22 Nov 2011, 01:26 PM
I have tried this:
Comment comment = new Comment(commentmessage); DocumentPosition startPosition = RadRichTextDocument.Document.Selection.Ranges.First.StartPosition; DocumentPosition endPosition = RadRichTextDocument.Document.Selection.Ranges.First.EndPosition; RadRichTextDocument.Document.InsertComment(startPosition, endPosition, comment);But nothing seems to happen... Is there anything i'm missing out?RadRichTextDocument.UpdateLayout();
0
![](/forums/images/avatarimages/default.gif)
Marcel
Top achievements
Rank 1
answered on 22 Nov 2011, 04:45 PM
Answer to my question:
RadRichTextDocument.ShowComments = true; // I WAS MISSING THIS OUT!!! DocumentPosition startPosition = RadRichTextDocument.Document.CaretPosition; DocumentPosition endPosition = new DocumentPosition(startPosition); startPosition.MoveToFirstPositionInParagraph(); endPosition.MoveToLastPositionInParagraph(); RadRichTextDocument.Document.InsertComment(startPosition, endPosition, new Comment(commentmessage));
0
Hello Chez,
Mihail
the Telerik team
We are glad you found out the solution to the problem. Lets us know if you experience any other setbacks.
Best wishes,Mihail
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
0
![](/forums/images/avatarimages/default.gif)
Marcel
Top achievements
Rank 1
answered on 12 Dec 2011, 05:55 PM
Hi, I have managed to delete all the comments in the document using: CommentRangeStart[] cR= RadRichTextDocument.Document.EnumerateChildrenOfType<CommentRangeStart>().ToArray(); for (int i = 0; i < cR.Length; i++) { CommentRangeStart currentC = cR[i]; start.MoveToInline(currentC.FirstLayoutBox as InlineLayoutBox, 0); end.MoveToInline(currentC.End.FirstLayoutBox as InlineLayoutBox, 0); end.MoveToNextInline(); RadRichTextDocument.DeleteComment(currentComment); } But I want to delete a comment which is within the currently selected text, how would i go about doing this? Thanks
0
Hello Chez,
In this way, all comments that have their start within the selection will be removed. You can further customize this solution to check if the CommentRangeEnd is within the selection instead of CommentRangeStart or check if both the start and end of the comment are within the selection.
However, you should have in mind that each delete operation will be registered separately in the history stack and undo/redo will add/remove only one comment at a time. I hope this helps. Greetings,
Iva Toteva
the Telerik team
You can get the boxes in the selection and remove all comments like this:
if
(!
this
.editor.Document.Selection.IsEmpty)
{
IEnumerable<InlineLayoutBox> selectedBoxes =
this
.editor.Document.Selection.GetSelectedBoxes().ToList<InlineLayoutBox>();
foreach
(InlineLayoutBox inlineBox
in
selectedBoxes)
{
if
(inlineBox.AssociatedInline
is
CommentRangeStart)
{
this
.editor.DeleteComment((CommentRangeStart)inlineBox.AssociatedInline);
}
}
}
In this way, all comments that have their start within the selection will be removed. You can further customize this solution to check if the CommentRangeEnd is within the selection instead of CommentRangeStart or check if both the start and end of the comment are within the selection.
However, you should have in mind that each delete operation will be registered separately in the history stack and undo/redo will add/remove only one comment at a time. I hope this helps. Greetings,
Iva Toteva
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>