Solution to the richeditcontrol contentchanged event twice

Source: Internet
Author: User

It's almost okay. After learning about devexpress, we used the richeditcontrol Control. When loading an object, we found that the contentchanged event was triggered twice.

I thought about it for half an hour. So I went to the official website to download the official documentation and suddenly realized that. Forgive me for the following:

Note that methods such as devexpress. xtrarichedit. API. Native. subdocument. inserttext and devexpress. xtrarichedit. API. Native. subdocument. insertdocumentcontent result in significant changes of the internal document model.ContentchangedEvent occurs two times in this case, and you cannot predict when the secondContentchangedEvent fires.

To distinguish between loading a new document and a situation when the document is modified, use the modified property within the event handler. when a document is newly created using the createnewdocument method, loaded from a file or from a stream, or created by assigning a value to a certain text property,ModifiedValue isFalse. Otherwise, it is setTrue.

 

This means that when inserttext and insertdocumentcontent are used, the internal structure of the document changes. In this case,ContentchangedThe event is triggered twice and cannot be predicted.

When is the second trigger.

To distinguish whether a new document is loaded or the document is changed, you can use the modified attribute in event processing. When a document is loaded from a file or stream through the createnewdocument method, or

When you create text attributes by specifying some values, the value of the modified attribute is false. In other cases, the value is true.

 

In other words, you can add the following code to event processing:

If (this. richeditcontrol1.modified) // when the content of a non-new file is changed
{
// Dosomething
}

Else // newly created File

{

// Dosomething

}

 

Solution to the richeditcontrol contentchanged event twice

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.