CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2010
    Posts
    2

    Pass data from a rich text field in ms access database to a richtextbox control

    Hi
    I have a simple MS Access database with some rich text fields. I have been trying to
    bind some RichTextBox controls in my form to these fields. When I used the following c# code blcok:
    Code:
       Binding bd = new Binding("Text", ds, "Words.meaning", true);
                tbDesc.DataBindings.Add(bd);
    ds= my DataSet
    Words= my Table
    meaning=A richtext field in my table

    when I executed this code, I got a non rich text tagged with rtf lables:
    <div>text</div> which I do not need.
    I want exactly the rich text to be displayed on the RichTextBox. So I binded the "Rtf" property of my richtextbox to the dataset:
    Code:
       Binding bd = new Binding("Rtf", ds, "Words.meaning", true);
                tbDesc.DataBindings.Add(bd);
    But I got nothing on the RichTextBox.
    I don't know why it is not showing anything!
    Can you suggest a way to bind a richtextbox and get the proper results?
    Thanks in advance

  2. #2
    Join Date
    Dec 2007
    Posts
    234

    Re: Pass data from a rich text field in ms access database to a richtextbox control

    Huh... interesting... the only difference between what you've done and what I've done in the past is that I'm used to binding to a specific object (as opposed to a dataset). Also, I pass False for the formatting parameter... try changing that and see if it makes a difference.

    Umm..... I'm re-reading your post... the snip you posted: <div>text</div> Ummm... that's HTML, not RTF. They're not compatible. Can you post what your raw data looks like? (like when you bound it to the Text property .... what was the result?)

    -tg
    * I don't respond to private requests for help. It's not conducive to the general learning of others.-I also subscribe to all threads I participate, so there's no need to pm when there's an update.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help - how to remove eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to???
    * On Error Resume Next is error ignoring, not error handling(tm). * Use Offensive Programming, not Defensive Programming.
    "There is a major problem with your code, and VB wants to tell you what it is.. but you have decided to put your fingers in your ears and shout 'I'm not listening!'" - si_the_geek on using OERN
    MVP '06-'10

  3. #3
    Join Date
    Nov 2010
    Posts
    2

    Unhappy Re: Pass data from a rich text field in ms access database to a richtextbox control

    Thanks for your response.
    I tried to change the formatting parameter from true to false and then I got Argument Exception error.
    And about my raw data I just simply typed the word "text" in MS Access database.
    but executing the first code (in first post of the thread) I got <div>text</div> on my richTextBox which is indeed in html format!
    I don't know how to fix this.

  4. #4
    Join Date
    Dec 2007
    Posts
    234

    Re: Pass data from a rich text field in ms access database to a richtextbox control

    OK, the reason binding to the Rtf property doesn't work... it's not RTF. It's text. Straight up. The fact that it's HTML is actually irrelevant, since it is still just text. As such, you'll need to use a different component that can take HTML and mark it up. The only ones I can think of off the top of my head are designed to work on web sites, not in a WinForm.
    Now, if you simply typed "text" into the database field, and it's coming out <div>text</div>" then there's something in the middle between you and your database that is adding the div tags.
    In short what you need to be looking for is a WinForms-based HTML editor component of some kind.
    See if any of these are any help: http://www.google.com/search?q=winforms+html+editor

    -tg
    * I don't respond to private requests for help. It's not conducive to the general learning of others.-I also subscribe to all threads I participate, so there's no need to pm when there's an update.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help - how to remove eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to???
    * On Error Resume Next is error ignoring, not error handling(tm). * Use Offensive Programming, not Defensive Programming.
    "There is a major problem with your code, and VB wants to tell you what it is.. but you have decided to put your fingers in your ears and shout 'I'm not listening!'" - si_the_geek on using OERN
    MVP '06-'10

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured