RichTextControl Rtf property  
Author Message
mifisailka





PostPosted: Wed Jul 07 16:18:20 CDT 2004 Top

Dotnet >> RichTextControl Rtf property 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.

DotNet152  
 
 
Charles





PostPosted: Wed Jul 07 16:18:20 CDT 2004 Top

Dotnet >> RichTextControl Rtf property This is a multi-part message in MIME format.

------=_NextPart_000_004C_01C4642D.43760350
Content-Type: text/plain;
charset="Utf-8"
Content-Transfer-Encoding: quoted-printable

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 =3D ADataset.Tables("TableName").Rows(0)

RichTextBox1.RTF =3D ADataRow("ColumnName")

Example 3.

Create A CommandObject and Fill the RichTextBox from the object

Dim ACommand as new Oledb.Command =3D AConnection.CreateCommand

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

AConnection.Open

RichTextBox1.RTF =3D ACommand.ExecuteScalar

AConnection.Close

Hope this helps,=20

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 =3D =
"{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fprq2\fcha=
rset0 Arial;}}\viewkind4\uc1\pard\f0\fs24 The remainder Of The Text Goes =
Here \par}"

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

The Result =3D

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


------=_NextPart_000_004C_01C4642D.43760350
Content-Type: text/html;
charset="Utf-8"
Content-Transfer-Encoding: quoted-printable

=EF=BB=BF<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; charset=3Dutf-8">
<META content=3D"MSHTML 6.00.2800.1400" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff background=3D"">
<DIV><FONT face=3DArial size=3D2>Hello,<BR><BR>I work with Jet4.0 =
Databases all the=20
time and use RichTextBoxes Often to retrieve RTF data from fields inside =
the=20
database.<BR><BR>I have never run into the problem you are expaining =
about=20
having a "@" at the beginning of the stored data.<BR><BR>How are you =
retrieving=20
the data into the RichTextBox. Here are some examples that work for=20
me.<BR><BR>Example 1,<BR><BR>Create A Dataset and bind the data to the =
rtf=20
property of the RichTextBox<BR><BR>RichTextBox1.DataBindings.Add("RTF",=20
ADataset, "TableName.ColumnName")<BR><BR>Example 2.<BR><BR>Create A =
Dataset and=20
Fill the RichTextBox from a DataRow<BR><BR>Dim ADataRow as DataRow =3D=20
ADataset.Tables("TableName").Rows(0)<BR><BR>RichTextBox1.RTF =3D=20
ADataRow("ColumnName")<BR><BR>Example 3.<BR><BR>Create A CommandObject =
and Fill=20
the RichTextBox from the object<BR><BR>Dim ACommand as new Oledb.Command =
=3D=20
AConnection.CreateCommand<BR><BR>ACommand.CommandText =3D "Select * FROM =
TableName=20
WHERE ID =3D 1"<BR><BR>AConnection.Open<BR><BR>RichTextBox1.RTF =3D=20
ACommand.ExecuteScalar<BR><BR>AConnection.Close<BR><BR>Hope this helps,=20
<BR><BR>Chuck<BR><BR>Maybe I am misunderstanding your question.&nbsp; =
Are you=20
trying to add a "@" before the text in the RTF Box?<BR>If so try =
this:<BR><BR>If=20
the font and RTF is always going to be the same, you can add a "@" into =
the RTF=20
by parsing the string and inserting a character into it after the RTF=20
Header.<BR></FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Dim AString as string =3D=20
"{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fprq2\fcha=
rset0=20
Arial;}}\viewkind4\uc1\pard\f0\fs24 The remainder Of The Text Goes=20
Here&nbsp;\par}"<BR></FONT></DIV>
<DIV><FONT face=3DArial size=3D2>AString =3D AString.Insert(114, =
"@")</FONT></DIV>
<P><FONT face=3DArial size=3D2>RichTextBox1.Rtf =3D AString</FONT></P>
<DIV><FONT face=3DArial size=3D2>The Result =3D</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT><BR><FONT face=3DArial=20
size=3D2>{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fp=
rq2\fcharset0=20
Arial;}}\viewkind4\uc1\pard\f0\fs24 @ The remainder Of The Text Goes=20
Here&nbsp;\par}"<BR><BR></FONT></DIV></BODY></HTML>

------=_NextPart_000_004C_01C4642D.43760350--

 
 
Charles





PostPosted: Thu Jul 08 16:41:25 CDT 2004 Top

Dotnet >> RichTextControl Rtf property 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