Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 698
  • Last Modified:

RichTextBox bound to string field in dataset shows the RTF codes

I have an ap in VS 2005.  A form is bound to a dataset.  A RichTextBox is bound to a string field which contains RTF Text.  Most of the data was entered in a similar program witten in VB6.  Now all the RTF codes are visible in the text box - it seems to be showing them as plain text without interpreting them.  If I enter new data in an empty record it works fine - the text is visible without the RTF codes.  It worked OK in VS2003 once I bound the data to the correct property of the RichTextBox but VS2005 does not seem to let you do that.

How doI get the formatted text to appear correctly?
1 Solution
VB.NET 2005 will allow you to do it.  But you have to do it in code as the RichTextBox's .rtf property does not appear in the IDE GUI.  These lines are working for me in a quick VB.NET 2005 test form I just coded.

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'TODO: This line of code loads data into the 'TestDataSet.MyRTF' table. You can move, or remove it, as needed.
        RichTextBox1.DataBindings.Add("rtf", BindingSource1, "MyText")
    End Sub

One other problem that I've experienced is that on saving .rtf to a database the coded string has had a Chr(0) added at the end and, when that is read back, it throws the display.  Here's a post that touches on that


MikeVEAuthor Commented:
Thanks Roger

That did the trick.  I checked the names of the two RichTextBoxes concerned and searched the Designer.vb file for the relevant Databinding line, copied them to the ordinary file and there changed the "Text" parameter to "RTF".

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now