officefileapi-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-subdocument-dot-delete-x28-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-documentrange-x29.md
Removes content from the specified range.
Namespace : DevExpress.XtraRichEdit.API.Native
Assembly : DevExpress.RichEdit.v25.2.Core.dll
NuGet Package : DevExpress.RichEdit.Core
void Delete(
DocumentRange range
)
Sub Delete(
range As DocumentRange
)
| Name | Type | Description |
|---|---|---|
| range | DocumentRange |
A range with the content to delete.
|
Use the Delete method to remove document content (text, images, etc.) located in the specified range.
The code sample below removes specific words from a document:
using DevExpress.XtraRichEdit.API.Native;
using (RichEditDocumentServer wordProcessor = new RichEditDocumentServer())
{
wordProcessor.LoadDocument("FirstLook.docx");
RemoveSpecificWords(wordProcessor.Document);
}
static void RemoveSpecificWords(Document document)
{
string word = "Ounce";
DocumentRange[] found = document.FindAll
(word, SearchOptions.WholeWord);
foreach (DocumentRange range in found)
{
document.Delete(range);
}
}
Imports DevExpress.XtraRichEdit.API.Native
Using wordProcessor As New RichEditDocumentServer()
wordProcessor.LoadDocument("FirstLook.docx")
RemoveSpecificWords(wordProcessor.Document)
End Using
static void RemoveSpecificWords(Document document)
Dim word As String = "Ounce"
Dim found() As DocumentRange = document.FindAll
(word, SearchOptions.WholeWord)
For Each range As DocumentRange In found
document.Delete(range)
Next range
End Sub
If the DocumentRange passed as the method parameter contains only table cells without the text surrounding the table, the Delete method clears the only the cells content. If you want do delete a table row or other table elements, utilize the following methods instead:
To delete a nested field, set the parent field’s ShowCodes property to true. Use the Field.Parent property to access the parent field.
The following code snippets (auto-collected from DevExpress Examples) contain references to the Delete(DocumentRange) 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.
word-processing-merge-documents-with-different-headers-and-footers/CS/Helpers/SectionsMerger.cs#L31
SubDocument target = targetSection.BeginUpdateHeader(headerFooterType);
target.Delete(target.Range);
target.InsertDocumentContent(target.Range.Start, source.Range, InsertOptions.KeepSourceFormatting);
word-document-api-examples/CS/CodeExamples/BasicActions.cs#L64
// Delete the first empty paragraph.
tempWordProcessor.Document.Delete(tempWordProcessor.Document.Paragraphs.First().Range);
// Save the document page as an RTF file.
winforms-richedit-document-api/CS/RichEditAPISample/CodeExamples/Notes.cs#L53
//Clear the range:
footnote.Delete(noteTextRange);
wpf-richedit-document-api/CS/DXRichEditControlAPISample/CodeExamples/NotesActions.cs#L53
//Clear the range:
footnote.Delete(noteTextRange);
winforms-richeditcontrol-common-api/CS/RichEditAPISample/CodeExamples/RichEditControlActions.cs#L482
DocumentRange rangeToRemove = doc.CreateRange(range.Start, selLength);
doc.Delete(rangeToRemove);
range.EndUpdateDocument(doc);
word-processing-merge-documents-with-different-headers-and-footers/VB/Helpers/SectionsMerger.vb#L30
Dim target As SubDocument = targetSection.BeginUpdateHeader(headerFooterType)
target.Delete(target.Range)
target.InsertDocumentContent(target.Range.Start, source.Range, InsertOptions.KeepSourceFormatting)
word-document-api-examples/VB/CodeExamples/BasicActions.vb#L61
' Delete the first empty paragraph.
tempWordProcessor.Document.Delete(System.Linq.Enumerable.First(Of DevExpress.XtraRichEdit.API.Native.Paragraph)(tempWordProcessor.Document.Paragraphs).Range)
' Save the document page as an RTF file.
winforms-richedit-document-api/VB/RichEditAPISample/CodeExamples/Notes.vb#L40
'Clear the range:
footnote.Delete(noteTextRange)
'Append a new text:
wpf-richedit-document-api/VB/DXRichEditControlAPISample/CodeExamples/NotesActions.vb#L47
'Clear the range:
footnote.Delete(noteTextRange)
winforms-richeditcontrol-common-api/VB/RichEditAPISample/CodeExamples/RichEditControlActions.vb#L500
Dim rangeToRemove As DocumentRange = doc.CreateRange(range.Start, selLength)
doc.Delete(rangeToRemove)
range.EndUpdateDocument(doc)
See Also