This is a migrated thread and some comments may be shown as answers.

Read-only range from the start or to the end of the document

2 Answers 70 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Vladimir
Top achievements
Rank 1
Vladimir asked on 07 Aug 2020, 12:05 PM

Hello, I have a document with a predefined structure locked by read-only ranges. Users are allowed to edit only small portions of it in the middle. But I cannot find a way to prevent them editing the beginning of the document before the first read-only range or at the end of the document after the last read-only range. Is there some way to achieve this?

Best regards, 

Vitalij

2 Answers, 1 is accepted

Sort by
0
Accepted
Tanya
Telerik team
answered on 12 Aug 2020, 06:58 AM

Hi Vitalij,

Placing the caret next to a read-only range actually places it just before or after it but still outside of it. That is why the users can edit at the start and at the end of the document. You can bypass that behavior by canceling the commands when the caret is at these specific positions. To implement this, you will need to attach to the CommandExecuting event of RadRichTextBox and execute the following code inside its handler:

private void RadRichTextBox_CommandExecuting(object sender, Telerik.Windows.Documents.RichTextBoxCommands.CommandExecutingEventArgs e)
{
    if (this.radRichTextBox.Document.CaretPosition.IsPositionAtDocumentStart || this.radRichTextBox.Document.CaretPosition.IsPositionAtDocumentEnd)
    {
        e.Cancel = true;
    }
}

Hope this is helpful.

Regards,
Tanya
Progress Telerik

0
Vladimir
Top achievements
Rank 1
answered on 17 Aug 2020, 02:11 PM

Hello Tanya, so far your solution is working as intended.

 

Thanks, Vitalij

Tags
RichTextBox
Asked by
Vladimir
Top achievements
Rank 1
Answers by
Tanya
Telerik team
Vladimir
Top achievements
Rank 1
Share this question
or