Results 1 to 3 of 3

Thread: RichTextBox with BindingSource

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2014
    Posts
    354

    RichTextBox with BindingSource

    I have VB6 app with multiple RichTextBoxes. They display strings from the database. Some records are in simple text format, some in Rtf because initially data was only in a simple format and there were just TextBoxes, later the database and app was modified.
    Standard TextBoxws were replaced with RichTextBoxes. I hade no problem with this kind of upgrade.
    In VB.Net I'm trying to display the same fields from DB which are presented in both simple and Rtf formats. If data value was modified in the VB6 app and saved in Rtf format then it is good in VB.Net, if it is still in a simple format then RichTextBox control in VB.Net is blank.
    I'm using BindingSource object like this:

    Code:
    rtbNotes.DataBindings.Add("Text", bdsSupplier, "Note") 'Gives entire text with formatting code in case of the value with formatting code and proper value if it is not with formatting codes.
    rtbNotes.DataBindings.Add("Rtf", bdsSupplier, "Note")'Displays good formatted value if value contains the formatting characters and doesn't display anything if there is no formatting.
    How can I make the RichTextBox in VB.Net work similar to VB6 (display value without formatting characters if they are there)?

    Thank you.

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    105,180

    Re: RichTextBox with BindingSource

    It sounds like your best option may be to not use data-binding. You can handle the appropriate event of your BindingSource move the data around yourself. You can then determine whether the data is RTF or not and set the appropriate property directly.

    An alternative would be to create your own control that inherits RichTextBox and adds a property that is able to do the detection and bind to that. Such a property could do as suggested above, i.e. detect format and then set the appropriate base property, or it could do an in-place upgrade of plain text to RTF.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2014
    Posts
    354

    Re: RichTextBox with BindingSource

    I found an easier way - I updated plain values to RTF format. Old VB6 RichTextBox controls work as before and VB.Net RichTextBoxes work fine now.
    Your advice requires much more work.
    Anyway thank you very much.

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