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

Determine if document has changed

4 Answers 171 Views
RichTextBox (obsolete as of Q3 2014 SP1)
This is a migrated thread and some comments may be shown as answers.
Jeff Clark
Top achievements
Rank 1
Jeff Clark asked on 28 Jul 2011, 08:01 PM
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.

4 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 02 Aug 2011, 02:44 PM
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 >>
0
Jeff Clark
Top achievements
Rank 1
answered on 15 Aug 2011, 07:17 PM
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.
0
Accepted
Stefan
Telerik team
answered on 16 Aug 2011, 02:47 PM
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 >>

0
Accepted
Jeff Clark
Top achievements
Rank 1
answered on 02 Sep 2011, 09:54 PM
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.
Tags
RichTextBox (obsolete as of Q3 2014 SP1)
Asked by
Jeff Clark
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Jeff Clark
Top achievements
Rank 1
Share this question
or