Results 1 to 4 of 4

Thread: unable to pass rich text from form to form

  1. #1

    Thread Starter
    Registered User
    Join Date
    Oct 2021
    Posts
    1

    unable to pass rich text from form to form

    Hi guys,

    I have a situation whereby unable to pass rich text from one form to another with error "File format is not valid". Below is my code. Would appreciate deeply with some help here. Thanks


    Private Sub lvCode_MouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lvCode.MouseDoubleClick

    Dim vCode, vDescription As String
    items = lvCode.SelectedItems(0).SubItems(1).Text
    vDescription = SetAccessValue(items)
    frmMain.txtMICHS.Rtf = Chr(13) & frmMain.txtMICHS.Rtf & Chr(13) & vDescription
    end sub

    Private items As String = String.Empty
    Public Function SetAccessValue(ByVal value As String) As String
    items = value
    Return items
    End Function

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    24,401

    Re: unable to pass rich text from form to form

    SetAccessValue Is redundant. You’re just passing in a string and returning it unchanged…

    What exactly does lvCode.SelectedItems(0).SubItems(1).Text contain?

  3. #3
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    107,760

    Re: unable to pass rich text from form to form

    You can't just put random bits of text together and expect it to be valid RTF. RTF has rules and you are not following them, so the resultant text is invalid. What you should do is set the SelectionStart property of the RichTextBox to the place in the existing text that you want to insert new text and then set the SelectedText property to insert the new text. That will include that text but within valid RTF markup. In your case, you might do this:
    vb.net Code:
    1. frmMain.txtMICHS.SelectionStart = 0
    2. frmMain.txtMICHS.SelectedText = ControlChars.Lf
    3. frmMain.txtMICHS.SelectionStart = frmMain.txtMICHS.TextLength
    4. frmMain.txtMICHS.SelectedText = ControlChars.Lf & vDescription
    I can't recommend accessing controls on other forms directly like that, but that's another issue.

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    24,401

    Re: unable to pass rich text from form to form

    Code:
    vDescription = lvCode.SelectedItems(0).SubItems(1).Text
    frmMain.txtMICHS.Rtf = "\r\n" & frmMain.txtMICHS.Rtf & "\r\n" & vDescription

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