History

The RadDocument class can track the history of any actions taken against its content. In this way it allows an undo and redo functionality to be easily implemented. The history is implemented via the DocumentHistory class and the RadDocument exposes the History property of this type. The RadRichTextBox automatically adds and removes items from the history, when its API methods get called, but you are allowed to manually work with the history as well.

To learn more about the DocumentHistory API read here.

This topic will explain you how to:

Enable/Disable History

You can enable or disable the history for the RadDocument via the Enabled property of the DocumentHistory.

this.radRichTextBox.Document.History.Enabled = false; 
Me.radRichTextBox.Document.History.Enabled = False 

Clear History

To clear the history you just have to call the Clear() method of the DocumentHistory class.

this.radRichTextBox.Document.History.Clear(); 
Me.radRichTextBox.Document.History.Clear() 

Undo/Redo Actions

To undo and redo some actions, you can call the Undo() and Redo() methods of the RadRichTextBox.

private void UndoAction() 
{ 
    this.radRichTextBox.Undo(); 
} 
private void RedoAction() 
{ 
    this.radRichTextBox.Redo(); 
} 
Private Sub UndoAction() 
 Me.radRichTextBox.Undo() 
End Sub 
Private Sub RedoAction() 
 Me.radRichTextBox.Redo() 
End Sub 

Change History Depth

To change the history capacity you have to set the desired value of the Depth property of the DocumentHistory. The default one is 1000.

this.radRichTextBox.Document.History.Depth = 500; 
Me.radRichTextBox.Document.History.Depth = 500 

Preserve History Using RadDocumentEditor

RadDocument has API of its own, but using it has a set of limitations. One of those limitations is that the methods of RadDocument are not registered in the undo/redo stack. Thus, once such a method is used, the history stack is cleared and users will no longer be able to undo and redo their previous changes. You can find detailed information on the topic here.

See Also

In this article