By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,719 Members | 1,875 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,719 IT Pros & Developers. It's quick & easy.

Problems with a richtext box and filling it with RTF data from SQL.

P: n/a
Hello..

I've been having some problems for a little while with this which I was
sure I would beat...hmmm.

Anyway, I have a form with two rich textboxes. One at the top which is
to display a concatenated summary, and one at the botton for making a
new entry.

When items are added in from the bottom box, I do this via a class
(call_detail.vb):

code from the click event of the submit button
------------------------------------------------

Dim mycall_detail As New call_detail

mycall_detail.reference = update_reference
mycall_detail.narrative = SpellCheckRichText1.Rtf.ToString
mycall_detail.add_narrative()

-------------------------------------------------
I then call the add_narrative function as so from the class

----------------------------------------
Public Function add_narrative()
Dim sqlcom As New SqlCommand
sqlcom.Connection = sqlcon
sqlcom.CommandType = CommandType.StoredProcedure
sqlcom.CommandText = "add_narrative"
sqlcom.Parameters.Add("@in_call_reference", reference)
sqlcom.Parameters.Add("@in_narrative", narrative)
sqlcom.Parameters.Add("@in_user", System.Environment.UserName)
If sqlcon.State <> ConnectionState.Open Then sqlcon.Open()

sqlcom.ExecuteNonQuery()

End Function
----------------------------------------
This calls a SQL Stored proc: as so

------------------------------------------
dbo.add_narrative

@in_call_reference int,
@in_narrative text,
@in_user char(40)

AS

insert into call_details(

call_reference,narrative,entered_by,date_entered)

values(@in_call_reference,@in_narrative,@in_user,g etdate()
----------------------------------------------
This seems to add the data into the narrative table fine. one of the
entries in the narrative.narrative field contains:

{\rtf1\ansi\ansicpg1252\uc1\deff0\stshfdbch0\stshf loch0\stshfhich0\stshfbi0\deflang2057\deflangfe205 7{\fonttbl{\f0\froman\fcharset0\fprq2{\*\panose
02020603050405020304}Times New Roman;} test
This is the output from the rtf.tostring of the lower rich text box.
I can read that data back into a string no problem, but getting it to
show as formatted rich text is where I'm having problems - it only ever
displays literally.

I use a function in my class called_populate memo:

---------------------------------------------
Public Function populate_memo()
' Lets use a sqldata reader to get our text properties!!!
Dim retval As String

Dim sqlcom As New SqlCommand
sqlcom.Connection = sqlcon
sqlcom.CommandType = CommandType.StoredProcedure
sqlcom.CommandText = "get_verbose_narratives"
sqlcom.Parameters.Add("@in_call", reference)

Dim narr_reader As SqlDataReader
If sqlcon.State <> ConnectionState.Open Then sqlcon.Open()

narr_reader = sqlcom.ExecuteReader

C_memo = Nothing

While narr_reader.Read

memo += Trim(narr_reader.GetString(2)) & " on " &
narr_reader.GetDateTime(1) & vbNewLine
memo += "----------------------------------------------" &
vbNewLine
memo += narr_reader.GetString(0)
memo += vbNewLine & vbNewLine

End While

End Function

-------------------------------------------------
This calls the following stored procedure:

---------------------------------------

dbo.get_verbose_narratives

@in_call int

as

SELECT narrative,date_entered, entered_by
FROM call_details
WHERE (call_reference = @in_call)
ORDER BY narrative_id

--------------------------------------------
And finally here is the code I use when trying to pass the contents of
the "memo" property of my class into the upper rich text box.

------------------------------------------

Dim mycalldetail As New call_detail
mycalldetail.reference = update_reference
mycalldetail.populate_memo()

MessageBox.Show(mycalldetail.memo)
RichTextBox1.AppendText(mycalldetail.memo)

--------------------------------------------

I'm presuming this is a cast / type issue of sorts as if I create a
richtext document called jc.rtf and call :
' RichTextBox1.LoadFile("d:\jc.rtf")

instead of the appendtext line it works fine.

I toyed with the idea of creating temporary richtext files to read
from, but don't like that idea at all...

I know this is all a little vague, but can anyone throw any light on
this? Am I making a fundemental error?

Many Thanks :-)

JC

Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
This is because AppendText is an inherited method from TextBoxBase and has
not knowledge of the RTF. You will need to walk the string with selection
and re-establish the format. This seems rather naff to me actually, I cant
see any other way of doing it other than as you say use temporatr files.

If you do however want to walk the string, you are going to need to parse
the formatting . . .

If anyone has found a better way to do this I would like to see it.

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"JC - home" <jo**@johnclark.me.uk> wrote in message
news:10**********************@h37g2000oda.googlegr oups.com...
Hello..

I've been having some problems for a little while with this which I was
sure I would beat...hmmm.

Anyway, I have a form with two rich textboxes. One at the top which is
to display a concatenated summary, and one at the botton for making a
new entry.

When items are added in from the bottom box, I do this via a class
(call_detail.vb):

code from the click event of the submit button
------------------------------------------------

Dim mycall_detail As New call_detail

mycall_detail.reference = update_reference
mycall_detail.narrative = SpellCheckRichText1.Rtf.ToString
mycall_detail.add_narrative()

-------------------------------------------------
I then call the add_narrative function as so from the class

----------------------------------------
Public Function add_narrative()
Dim sqlcom As New SqlCommand
sqlcom.Connection = sqlcon
sqlcom.CommandType = CommandType.StoredProcedure
sqlcom.CommandText = "add_narrative"
sqlcom.Parameters.Add("@in_call_reference", reference)
sqlcom.Parameters.Add("@in_narrative", narrative)
sqlcom.Parameters.Add("@in_user", System.Environment.UserName)
If sqlcon.State <> ConnectionState.Open Then sqlcon.Open()

sqlcom.ExecuteNonQuery()

End Function
----------------------------------------
This calls a SQL Stored proc: as so

------------------------------------------
dbo.add_narrative

@in_call_reference int,
@in_narrative text,
@in_user char(40)

AS

insert into call_details(

call_reference,narrative,entered_by,date_entered)

values(@in_call_reference,@in_narrative,@in_user,g etdate()
----------------------------------------------
This seems to add the data into the narrative table fine. one of the
entries in the narrative.narrative field contains:

{\rtf1\ansi\ansicpg1252\uc1\deff0\stshfdbch0\stshf loch0\stshfhich0\stshfbi0\
deflang2057\deflangfe2057{\fonttbl{\f0\froman\fcha rset0\fprq2{\*\panose 02020603050405020304}Times New Roman;} test
This is the output from the rtf.tostring of the lower rich text box.
I can read that data back into a string no problem, but getting it to
show as formatted rich text is where I'm having problems - it only ever
displays literally.

I use a function in my class called_populate memo:

---------------------------------------------
Public Function populate_memo()
' Lets use a sqldata reader to get our text properties!!!
Dim retval As String

Dim sqlcom As New SqlCommand
sqlcom.Connection = sqlcon
sqlcom.CommandType = CommandType.StoredProcedure
sqlcom.CommandText = "get_verbose_narratives"
sqlcom.Parameters.Add("@in_call", reference)

Dim narr_reader As SqlDataReader
If sqlcon.State <> ConnectionState.Open Then sqlcon.Open()

narr_reader = sqlcom.ExecuteReader

C_memo = Nothing

While narr_reader.Read

memo += Trim(narr_reader.GetString(2)) & " on " &
narr_reader.GetDateTime(1) & vbNewLine
memo += "----------------------------------------------" &
vbNewLine
memo += narr_reader.GetString(0)
memo += vbNewLine & vbNewLine

End While

End Function

-------------------------------------------------
This calls the following stored procedure:

---------------------------------------

dbo.get_verbose_narratives

@in_call int

as

SELECT narrative,date_entered, entered_by
FROM call_details
WHERE (call_reference = @in_call)
ORDER BY narrative_id

--------------------------------------------
And finally here is the code I use when trying to pass the contents of
the "memo" property of my class into the upper rich text box.

------------------------------------------

Dim mycalldetail As New call_detail
mycalldetail.reference = update_reference
mycalldetail.populate_memo()

MessageBox.Show(mycalldetail.memo)
RichTextBox1.AppendText(mycalldetail.memo)

--------------------------------------------

I'm presuming this is a cast / type issue of sorts as if I create a
richtext document called jc.rtf and call :
' RichTextBox1.LoadFile("d:\jc.rtf")

instead of the appendtext line it works fine.

I toyed with the idea of creating temporary richtext files to read
from, but don't like that idea at all...

I know this is all a little vague, but can anyone throw any light on
this? Am I making a fundemental error?

Many Thanks :-)

JC

Nov 21 '05 #2

P: n/a
I guess writing a procedure to walk the string wouldn't be too
difficult, just time consuming on something that should be
straightforward.... I was thinking of being able to paste screenshots
into the rtf box as well though..... oh well!!! ;-)

Perhaps there is a custom control out there somewhere that will save me
the time on this one!

JC

Nov 21 '05 #3

P: n/a
As the upper text box is only intended to show RTF, anyone have any
suggestions on any other controls that would recognise the rtf format -
all clients will have msoffice XP installed.......

Nov 21 '05 #4

P: n/a
Sorry to use this group as a dumping ground for my thoughts... I guess
I could create a crystal report (or other reporting tool as I really
don't like crystal that much) and have that interpret the text as
rtf.......

Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.