RichTextControl Rtf property

G

Guest

I have an application that simply reads the text in a RichTextBox control, and stores the text into the database. I want to use the plain RichTextBox control and not a database rtf control.

When I read the Rtf property it returns the text combined with rft codes, e.g.:
"{\\rtf1 ....... \r\0"

I then store this text in my Access database via an OdbcCommand. When I read the text back from the database, the returned text is @-quoted as follows:
@"{\\rtf1 ....... \r\0"

When I try to set the RichTextControl Rtf property with the value from the database an exception is thrown.

It would appear that the Rtf property cannot accept @-quoted values (e.g. a value of

@"This is a test"

will cause an error.

How can I work around this problem while still using the RichTextControl in the scheme above.
 
C

Charles A. Lackman

Hello,

I work with Jet4.0 Databases all the time and use RichTextBoxes Often to retrieve RTF data from fields inside the database.

I have never run into the problem you are expaining about having a "@" at the beginning of the stored data.

How are you retrieving the data into the RichTextBox. Here are some examples that work for me.

Example 1,

Create A Dataset and bind the data to the rtf property of the RichTextBox

RichTextBox1.DataBindings.Add("RTF", ADataset, "TableName.ColumnName")

Example 2.

Create A Dataset and Fill the RichTextBox from a DataRow

Dim ADataRow as DataRow = ADataset.Tables("TableName").Rows(0)

RichTextBox1.RTF = ADataRow("ColumnName")

Example 3.

Create A CommandObject and Fill the RichTextBox from the object

Dim ACommand as new Oledb.Command = AConnection.CreateCommand

ACommand.CommandText = "Select * FROM TableName WHERE ID = 1"

AConnection.Open

RichTextBox1.RTF = ACommand.ExecuteScalar

AConnection.Close

Hope this helps,

Chuck

Maybe I am misunderstanding your question. Are you trying to add a "@" before the text in the RTF Box?
If so try this:

If the font and RTF is always going to be the same, you can add a "@" into the RTF by parsing the string and inserting a character into it after the RTF Header.

Dim AString as string = "{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fprq2\fcharset0 Arial;}}\viewkind4\uc1\pard\f0\fs24 The remainder Of The Text Goes Here \par}"

AString = AString.Insert(114, "@")
RichTextBox1.Rtf = AString

The Result =

{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fprq2\fcharset0 Arial;}}\viewkind4\uc1\pard\f0\fs24 @ The remainder Of The Text Goes Here \par}"
 
C

Charles A. Lackman

Hello,

I am glad that what was sent you to originally worked for you.
Consider the Following:


Dim InsertCommand As New OleDb.OleDbCommand()

InsertCommand.Connection = AConnection

NOTE: EVERY COLUMN INSIDE THE DATABASE MUST BE ACCOUNTED FOR IN THE INSERT
COMMAND

AnInsertString = "INSERT INTO MyTable VALUES (?,?);"

InsertCommand.CommandText = AnInsertString

InsertCommand.Parameters.Add("@ID", Data.OleDb.OleDbType.WChar)
InsertCommand.Parameters(0).Value = ID.Text

InsertCommand.Parameters.Add("@MyRTF",
Data.OleDb.OleDbType.WChar)
InsertCommand.Parameters(1).Value = RichTextBox.RTF

Try
AConnection.Open()
InsertCommand.ExecuteNonQuery()
AConnection.Close()
InsertCommand.Dispose()
Catch AnError As OleDb.OleDbException
AConnection.Close()
InsertCommand.Dispose()
End Try


Chuck
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top