Back to Devexpress

CommentCollection.Create(DocumentRange, String) Method

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

latest6.7 KB
Original Source

CommentCollection.Create(DocumentRange, String) Method

Creates a new Comment with the specified settings.

Namespace : DevExpress.XtraRichEdit.API.Native

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

NuGet Package : DevExpress.RichEdit.Core

Declaration

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

Parameters

NameTypeDescription
rangeDocumentRange

A DocumentRange for which a comment is being created.

| | author | String |

A String value that sets the Comment.Author property.

|

Returns

TypeDescription
Comment

A Comment object.

|

Remarks

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

Example

View Example

csharp
using DevExpress.XtraRichEdit.API.Native;
using DevExpress.XtraRichEdit;

static void CreateComment(RichEditDocumentServer wordProcessor) {

    // Load a document from a file.
    wordProcessor.LoadDocument("Documents\\Grimm.docx");

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

    if (document.Paragraphs.Count > 2) {
        // Access the range of the third paragraph.
        DocumentRange docRange = document.Paragraphs[2].Range;

        // Specify the comment's author name.
        string commentAuthor = "Johnson Alphonso D";

        // Create a comment.
        document.Comments.Create(docRange, commentAuthor, DateTime.Now);
    }
}
vb
Imports DevExpress.XtraRichEdit.API.Native
Imports DevExpress.XtraRichEdit

Shared Sub CreateComment(ByVal wordProcessor As RichEditDocumentServer)
    ' Load a document from a file.
    wordProcessor.LoadDocument("Documents\Grimm.docx")

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

    If document.Paragraphs.Count > 2 Then
        ' Access the range of the third paragraph.
        Dim docRange As DocumentRange = document.Paragraphs(2).Range

        ' Specify the comment's author name.
        Dim commentAuthor As String = "Johnson Alphonso D"

        ' Create a comment.
        document.Comments.Create(docRange, commentAuthor, Date.Now)
    End If
End Sub

The following code snippets (auto-collected from DevExpress Examples) contain references to the Create(DocumentRange, String) 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/SelectionCollection.cs#L114

csharp
Comment comment = document.Comments.Create(document.Selection, "");
SubDocument commentDoc = comment.BeginUpdate();

word-document-api-examples/CS/CodeExamples/ProtectionActions.cs#L33

csharp
// Create a comment related to the first paragraph.
document.Comments.Create(document.Paragraphs[0].Range, "Admin");

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

csharp
string commentAuthor = "Maryland B. Clopton";
    document.Comments.Create(docRange, commentAuthor);
}

winforms-richedit-document-api/VB/RichEditAPISample/CodeExamples/SelectionCollection.vb#L104

vb
document.Selections.Add(ranges)
Dim comment As DevExpress.XtraRichEdit.API.Native.Comment = document.Comments.Create(document.Selection, "")
Dim commentDoc As DevExpress.XtraRichEdit.API.Native.SubDocument = comment.BeginUpdate()

word-document-api-examples/VB/CodeExamples/ProtectionActions.vb#L31

vb
' Create a comment related to the first paragraph.
document.Comments.Create(document.Paragraphs(CInt((0))).Range, "Admin")
' Access the comment content.

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

vb
Dim commentAuthor As String = "Maryland B. Clopton"
    document.Comments.Create(docRange, commentAuthor)
End Sub

See Also

CommentCollection Interface

CommentCollection Members

DevExpress.XtraRichEdit.API.Native Namespace