Ticket T929068
Visible to All Users

How to bind a RichEditControl to a data field that contains plain and RTF text

created 5 years ago

Good Morning,

I am using your RichEditControl bound to a varchar max field of a SQL Server database and it is working great. The texts are stored into the field correctly and loading of the field content back into the RichEditControl is working fine as well.

Unfortunately the database table is not brand new and old records exists where the same field is used to store plain texts - so basically the contents are unformatted notes. In case a users selects one of the old records to be loaded into the RichEditControl the value of the RichEditControl stays empty.

Is there a work around you suggest to be able to open the old records with plain text in the RichEditControl as well? Or should I stop using the
same field to store "legacy" plain text and new RTF text and instead kind of "import" the plain text into the RichEditControl if I figure out
that that the record opened by the user ist "legacy" plain text record?

Thank you for your advice,

Sven

Answers approved by DevExpress Support

created 5 years ago

Hello Sven,

You can use our IFormatDetectorService service to determine if a data record has RTF data. Convert data from a database to a memory stream to load it to the IFormatDetectorService.DetectFormat method.

Alternatively, you can check if a string from the database starts with the "{\rtf1" prefix. If so, this string contains RTF data.

    Show previous comments (1)
    DevExpress Support Team 5 years ago

      I created a sample that demonstrates how to bind a data object to the RichEditControl.RtfText property and convert plain text to RTF using our non-visual RichEditDocumentServer component. You can find the project and video in the attachment.

        Thank you very much. This was very helpful!

        Cheers,

        Sven

        DevExpress Support Team 5 years ago

          You are welcome, Sven.

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.