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

3 posts, 1 answers
  1. Vitalij
    Vitalij avatar
    39 posts
    Member since:
    Dec 2010

    Posted 07 Aug 2020 Link to this post

    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. Answer
    Tanya
    Admin
    Tanya avatar
    918 posts

    Posted 12 Aug 2020 Link to this post

    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

  3. Vitalij
    Vitalij avatar
    39 posts
    Member since:
    Dec 2010

    Posted 17 Aug 2020 in reply to Tanya Link to this post

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

     

    Thanks, Vitalij

Back to Top