Back to Devexpress

CommentCollection.Create(String, Comment) Method

officefileapi-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-commentcollection-dot-create-x28-system-dot-string-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-comment-x29.md

latest6.8 KB
Original Source

CommentCollection.Create(String, Comment) Method

Creates a nested comment.

Namespace : DevExpress.XtraRichEdit.API.Native

Assembly : DevExpress.RichEdit.v25.2.Core.dll

NuGet Package : DevExpress.RichEdit.Core

Declaration

csharp
Comment Create(
    string author,
    Comment parentComment
)
vb
Function Create(
    author As String,
    parentComment As Comment
) As Comment

Parameters

NameTypeDescription
authorString

A String value that sets the Comment.Author property.

| | parentComment | Comment |

A Comment object that is the parent comment.

|

Returns

TypeDescription
Comment

A Comment object that is the nested comment

|

Remarks

Use the Create method to create a nested comment and add it to the collection of comments in a document.

Example

View Example

csharp
static void CreateNestedComment(RichEditDocumentServer wordProcessor) {
    // Load a document from a file.
    wordProcessor.LoadDocument("Documents\\Grimm.docx", DocumentFormat.Docx);

    // Access a document.
    Document document = wordProcessor.Document;

    if (document.Comments.Count > 1)
    {
        // Create a new comment nested in the parent comment.
        Comment newComment = document.Comments.Create("Vicars Anny", document.Comments[1]);
        newComment.Date = DateTime.Now;
        SubDocument commentDocument = newComment.BeginUpdate();
        commentDocument.InsertText(commentDocument.Range.Start, "I agree");
        newComment.EndUpdate(commentDocument);
    }
}
vb
Shared Sub CreateNestedComment(ByVal wordProcessor As RichEditDocumentServer)
    ' Load a document from a file.
    wordProcessor.LoadDocument("Documents\Grimm.docx", DocumentFormat.Docx)

    ' Access a document.
    Dim document As Document = wordProcessor.Document

    If document.Comments.Count > 1 Then
        ' Create a new comment nested in the parent comment.
        Dim newComment As Comment = document.Comments.Create("Vicars Anny", document.Comments(1))
        newComment.Date = Date.Now
        Dim commentDocument As SubDocument = newComment.BeginUpdate()
        commentDocument.InsertText(commentDocument.Range.Start, "I agree")
        newComment.EndUpdate(commentDocument)
    End If
End Sub

The following code snippets (auto-collected from DevExpress Examples) contain references to the Create(String, Comment) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

winforms-richedit-document-api/CS/RichEditAPISample/CodeExamples/Comments.cs#L24

csharp
if (resRanges.Length > 0) {
    Comment newComment = document.Comments.Create("Vicars Anny", document.Comments[1]);
    newComment.Date = DateTime.Now;

wpf-richedit-document-api/CS/DXRichEditControlAPISample/CodeExamples/CommentsActions.cs#L32

csharp
if (resRanges.Length > 0) {
    Comment newComment = document.Comments.Create("Vicars Anny", document.Comments[1]);
    newComment.Date = DateTime.Now;

word-document-api-examples/CS/CodeExamples/CommentsActions.cs#L55

csharp
// Create a new comment nested in the parent comment.
Comment newComment = document.Comments.Create("Vicars Anny", document.Comments[1]);
newComment.Date = DateTime.Now;

winforms-richedit-document-api/VB/RichEditAPISample/CodeExamples/Comments.vb#L23

vb
If resRanges.Length > 0 Then
    Dim newComment As DevExpress.XtraRichEdit.API.Native.Comment = document.Comments.Create("Vicars Anny", document.Comments(1))
    newComment.[Date] = System.DateTime.Now

wpf-richedit-document-api/VB/DXRichEditControlAPISample/CodeExamples/CommentsActions.vb#L30

vb
If resRanges.Length > 0 Then
    Dim newComment As Comment = document.Comments.Create("Vicars Anny", document.Comments(1))
    newComment.Date = DateTime.Now

word-document-api-examples/VB/CodeExamples/CommentsActions.vb#L49

vb
' Create a new comment nested in the parent comment.
Dim newComment As DevExpress.XtraRichEdit.API.Native.Comment = document.Comments.Create("Vicars Anny", document.Comments(1))
newComment.[Date] = System.DateTime.Now

See Also

CommentCollection Interface

CommentCollection Members

DevExpress.XtraRichEdit.API.Native Namespace