Link to home
Start Free TrialLog in
Avatar of msgl
msgl

asked on

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.
Avatar of plusone3055
plusone3055
Flag of United States of America image

Avatar of msgl
msgl

ASKER

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.
Avatar of msgl

ASKER

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?
Avatar of msgl

ASKER

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?

Avatar of msgl

ASKER

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?
ASKER CERTIFIED SOLUTION
Avatar of msgl
msgl

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial