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

Is it possible to load text in a richtextbox from a dataset?

It doesn't sound to complicated but I haven't found any article or such describing how to do it.

Basically I want to select a template name in a combobox, press a button and fetch selected template to the richtextbox with a web service that executes a stored procedure (sql server)

Does anyone of you have any tips about a useful article?

Thanks in advance.
0
msgl
Asked:
msgl
  • 5
1 Solution
 
msglAuthor Commented:
Hi plusone,

That wasn't exactly what I was looking for. The questions is:
If I have a dataset with data such as template id, template name, template description and template data
how do I load the template data into the richtextbox?

The data is stored as binary data in an image field on the server so I have to convert it to a string
but then? Most of the examples I have seen uses a openfiledialog but that isn't what I am looking for.

Thanks in advance.
0
 
msglAuthor Commented:
I guess I gave you a bad explanation of what I wanted to do and I will break it down in a few steps.

I have a web service that returns a datatable with selected (from a combobox) template. The datatable has one row with columns id, name, description and data.

I want to assign the data cell to a variable and then convert it from the byte array it is to a string and then load it into the textbox.

My question is how do I get the data cell value  into a variable?
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
msglAuthor Commented:
Ok I got the cell value and convert it to a string with:

        Dim TemplateData As Byte() = TemplateDataTableInstance.Rows(0).Item("TemplateData")
        Dim strTemplateData As String
        Dim enc As New System.Text.UTF8Encoding()
        strTemplateData = enc.GetString(TemplateData)

Now I just need to load the string into the textbox with something like
        Dim strDataFormat As String = DataFormats.Rtf
        Using ms As New MemoryStream(strTemplateData)
            Dim tr As New TextRange(rtbTemplate.Document.ContentStart, rtbTemplate.Document.ContentEnd)
            tr.Load(ms, strDataFormat)
        End Using
it breaks on the dim tr as new textrange line though, is it because  I use a flowdocument in the richtextbox and how do I fix that?

0
 
msglAuthor Commented:
I can load the TemplateData as byte() into the richtextbox but not if I convert it to a string,
With byte array I lose the RTF formatting though, any comments?
0
 
msglAuthor Commented:
why didn't I try the simplest thing first instead of wasting your time reading this heh

I simply do
        Dim tr As New TextRange(rtbTemplate.Document.ContentStart, rtbTemplate.Document.ContentEnd)
        tr.Text = strTemplateData

I feel so stupid now.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

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