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

Bind Data to RadRichTextBox

5 Answers 232 Views
RichTextBox (obsolete as of Q3 2014 SP1)
This is a migrated thread and some comments may be shown as answers.
Alan
Top achievements
Rank 1
Alan asked on 17 Jan 2012, 04:34 PM
Currently I am trying to bind data to a richtextbox and I am not getting any data populating.
I am currently using this to bind the data.
radRichTextBox1.DataBindings.Add("Text",ds,"Table.ColumnName",false,DataSourceUpdateMode.OnPropertyChanged);

I have verified I am only pulling one record..
I have done this with TextBoxes with no issue.
I have the feeling "Text" should be something else but I am unsure what.
Any help would be appreciated.

5 Answers, 1 is accepted

Sort by
0
Julian Benkov
Telerik team
answered on 20 Jan 2012, 12:08 PM
Hi Alan,

This is not a built-in functionality in the current implementation of RadRichTextBox. To provide this behavior, you can use TxtFormatProvider implementing the Binder component. Here is a solution using binding to a simple TextBox:

namespace Lab
{
    public partial class RichTextBoxForm1 : Form
    {
        public RichTextBoxForm1()
        {
            InitializeComponent();
            
            RadRichTextBinder binder = new RadRichTextBinder(this.radRichTextBox1);
            this.textBox1.DataBindings.Add("Text", binder, "Text", true, DataSourceUpdateMode.OnPropertyChanged);
        }
    }
 
    public class RadRichTextBinder : TxtFormatProvider
    {
        private RadRichTextBox richTextBox;
        public event EventHandler TextChanged;
 
        public RadRichTextBinder(RadRichTextBox richTextBox)
        {
            this.richTextBox = richTextBox;
            this.richTextBox.DocumentContentChanged += new EventHandler(richTextBox_DocumentContentChanged);
             
        }
 
        void richTextBox_DocumentContentChanged(object sender, EventArgs e)
        {
            OnTextChanged(new EventArgs());
        }
 
        protected virtual void OnTextChanged(EventArgs e)
        {
            if (this.TextChanged != null)
            {
                this.TextChanged(this, e);
            }
        }
 
        public string Text
        {
            get
            {
                return this.Export(this.richTextBox.Document);
            }
            set
            {
                this.richTextBox.DocumentContentChanged -= new EventHandler(richTextBox_DocumentContentChanged);
                this.richTextBox.Document = this.Import(value);
                OnTextChanged(new EventArgs());
                this.richTextBox.DocumentContentChanged += new EventHandler(richTextBox_DocumentContentChanged);
            }
        }
    }
}

I hope this helps.

Kind regards,
Julian Benkov
the Telerik team

SP1 of Q3’11 of RadControls for WinForms is available for download (see what's new).

0
Alan
Top achievements
Rank 1
answered on 20 Jan 2012, 09:22 PM
This takes care of the problem I was having but presents another problem... I am currently using using databinding from a grid to text fields to the text fields reflect what row is selected in the grid. The solution given handles the issue but does not bind the data in the grid to the data in the textbox, it only places the data in the grid in the textbox.
0
Julian Benkov
Telerik team
answered on 25 Jan 2012, 01:21 PM
Hello Alan,

I would kindly ask you to provide me with additional details about your scenario. It will be best if you can send us a sample project where we can reproduce the issue. This will allow us to understand the exact behavior and the circumstances in which it occurs. Thank you in advance.

I am looking forward to your reply.

Greetings,
Julian Benkov
the Telerik team

SP1 of Q3’11 of RadControls for WinForms is available for download (see what's new).

0
Alan
Top achievements
Rank 1
answered on 01 Feb 2012, 10:28 PM
disregard my previous message.
I do have one other question, what would be involved to convert this binder to work with html so a formatted text string could be bought in and moved out of the richtextboxes.
0
Julian Benkov
Telerik team
answered on 06 Feb 2012, 10:47 AM
Hello Alan,

You can change the base class of the binder to be HtmlFormatProvider and use this new html based binding component, but please keep in mind that this will decrease the performance of your application.

Do not hesitate to contact us if you have further questions or issues. 

Kind regards,
Julian Benkov
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Tags
RichTextBox (obsolete as of Q3 2014 SP1)
Asked by
Alan
Top achievements
Rank 1
Answers by
Julian Benkov
Telerik team
Alan
Top achievements
Rank 1
Share this question
or