Determine if document has changed

5 posts, 2 answers
  1. Jeff Clark
    Jeff Clark avatar
    15 posts
    Member since:
    Feb 2010

    Posted 28 Jul 2011 Link to this post

    Is there an easy way to determine if the open document has any changes?

    I want to prompt the user to see if they want to save the document when they try to close the document or open a new one, but only if the document has changed.

    Thanks.
  2. Stefan
    Admin
    Stefan avatar
    2890 posts

    Posted 02 Aug 2011 Link to this post

    Hello Jeff,

    Thank you for writing.

    You can determine whether a document has been changed by subscribing to the DocumentContentChanged event of the desired document.

    I hope that you find this information helpful. Should you have any other questions, do not hesitate to contact us.
     
    All the best,
    Stefan
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Jeff Clark
    Jeff Clark avatar
    15 posts
    Member since:
    Feb 2010

    Posted 15 Aug 2011 Link to this post

    Thanks for the reply.

    I created an event hanlder as follows:

    Form Constructor
    public frmEditEmail()
    {
        InitializeComponent();
        radRichTextBox1.Document.DocumentContentChanged += new EventHandler(Document_DocumentContentChanged);
    }



    Event Handler
    void Document_DocumentContentChanged(object sender, EventArgs e)
    {
        emailTextChanged = true;
        MessageBox.Show("DocumentContentChanged");
    }



    But the event handler is not firing when changes are made in the document. What am I doing wrong?  Thanks.
  5. Answer
    Stefan
    Admin
    Stefan avatar
    2890 posts

    Posted 16 Aug 2011 Link to this post

    Hello Jeff,

    Thank you for writing.

    I have tested this scenario and on my end it behaves correctly. A possible reason for which the event does not fire is if the document does not exist in the form's constructor. This is why, I would recommend that you subscribe to the event in the form Shown event (refer to the attached video). If this still does not work for you, please provide me with a sample project demonstrating the issue, so I can investigate it locally and provide you with adequate support.

    I am looking forward to your reply.

    All the best,
    Stefan
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

  6. Answer
    Jeff Clark
    Jeff Clark avatar
    15 posts
    Member since:
    Feb 2010

    Posted 02 Sep 2011 Link to this post

    Thanks. Subscribing to the event in the Shown event didn't work, but that is because I haven't assigned a document to the RadRichText control yet.  I subscribed to the event right after assigning a document to the control and now it is working.
    Thanks for your help.
Back to Top
UI for WinForms is Visual Studio 2017 Ready