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

How to bind to a richtextbox/document

1 Answer 128 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Olga
Top achievements
Rank 1
Olga asked on 31 Mar 2011, 07:07 PM
hello,

I have a database, where there are two columns called title and description that both contain text/strings. In the SL I have a treelist view that I bound to my database that displays the titles. I also have a rich textbox in the SL application I would like to bind to my description column. As I click through the title in the tree, I would like the description in my richtextbox to change depending on what title I select in the tree. I want to also to be able to change the font of the description in the rich textbox. I tried adding a raddocument to my rich text box and then binding the description to the Span of the document (I did this my creating a custom property). It works, but it is not a two way binding. I want the user to be able to change the description in the textbox, and when he clicks save to update the database. Any help would be appreciated.

Thanks,
Olga

1 Answer, 1 is accepted

Sort by
0
Iva Toteva
Telerik team
answered on 05 Apr 2011, 05:36 PM
Hi Olga,

There is a similar demo in this forum thread. It keeps the titles of the documents in a list box and not a treelist view, but the approach should be quite similar. You can use HtmlDataProvider, XamlDataProvider and RtfDataProvider to bind the content of the document. There is also a TxtDataProvider, that strips the text from all formatting. You can find more information on the use of data providers in this article.
As it comes to setting the font properties of the text in the rich text box, if you set a font family and font size on the rich text box and the property DocumentInheritsDefaultStyleSettings="True", these default values will be applied to all spans that do not have explicitly set font family/size. In case you wish to change the font settings on the whole text, you can programmatically select the whole document and invoke the corresponding methods like this:

this.richTextEditor.Document.Selection.SelectAll();
this.richTextEditor.ChangeFontFamily(new FontFamily("Comic Sans MS"));
this.richTextEditor.ChangeFontSize(Unit.PointToDip(16));
this.richTextEditor.Document.Selection.Clear();

Best wishes,
Iva
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
RichTextBox
Asked by
Olga
Top achievements
Rank 1
Answers by
Iva Toteva
Telerik team
Share this question
or