RadRichTextBox and RadDataEntry

3 posts, 0 answers
  1. victor palomares
    victor palomares avatar
    2 posts
    Member since:
    Jul 2009

    Posted 02 Apr 2014 Link to this post

    Hi,
    I am trying to use RadRichTextbox with RadDataEntry.
    On the EditorInitializing event I set the editor to be a RadRichEditor for a particular string field.
    However since there is no property for the Text in the editor I am not sure how to handle the binding in this case.

    Any pointer will be much appreciated. 
    Thanks
  2. victor palomares
    victor palomares avatar
    2 posts
    Member since:
    Jul 2009

    Posted 03 Apr 2014 in reply to victor palomares Link to this post

    I figured it out by myself. Instead of binding to RadRichTextBox I created a wrapper user control around it that controls the Text Properties

    I put the solution in case is useful for anyone:

    01.public partial class RtlfWrapper : UserControl
    02.    {
    03.        public event EventHandler RtlfTextChanged;
    04. 
    05.        public RtlfWrapper()
    06.        {
    07.            InitializeComponent();
    08.        }
    09. 
    10.        private void radRichTextBox1_DocumentContentChanged(object sender, EventArgs e)
    11.        {
    12.            OnRtlfTextChanged();
    13.        }
    14. 
    15. 
    16.        public string RtlfText
    17.        {
    18.            get
    19.            {
    20.                var formatProvider = new RtfFormatProvider();
    21.                return formatProvider.Export(radRichTextBox1.Document);
    22.                 
    23.            }
    24.            set
    25.            {
    26.                radRichTextBox1.DocumentContentChanged -= radRichTextBox1_DocumentContentChanged;
    27. 
    28.                try
    29.                {
    30.                    ImportDocument(value);
    31.                }
    32.                catch
    33.                {
    34.                    InsertText(value);
    35.                }
    36. 
    37.                OnRtlfTextChanged();
    38.                radRichTextBox1.DocumentContentChanged += radRichTextBox1_DocumentContentChanged;
    39.            }
    40.        }
    41. 
    42.        private void ImportDocument(string value)
    43.        {
    44.            var formatProvider = new RtfFormatProvider();
    45.            radRichTextBox1.Document = formatProvider.Import(value);
    46.        }
    47. 
    48.        private void InsertText(string value)
    49.        {
    50.            var span = new Span(value);
    51.            var paragraph = new Paragraph();
    52.            var section = new Section();
    53.            var document = new RadDocument();
    54. 
    55.            paragraph.Inlines.Add(span);
    56.            section.Blocks.Add(paragraph);
    57.            document.Sections.Add(section);
    58. 
    59.            radRichTextBox1.Document = document;
    60.        }
    61. 
    62.        protected virtual void OnRtlfTextChanged()
    63.        {
    64.            var handler = RtlfTextChanged;
    65.            if (handler != null) handler(this, EventArgs.Empty);
    66.        }
    67.    }
  3. UI for WinForms is Visual Studio 2017 Ready
  4. George
    Admin
    George avatar
    500 posts

    Posted 07 Apr 2014 Link to this post

    Hello Victor,

    I am glad that you found a solution to your problem. We appreciate that you are sharing it with the community.

    Do not hesitate to let us know should you have any further questions.

    Regards,
    George
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top