Profile Picture

RTF string loses table formatting from RichTextView

Posted By Tom Galczynski 2 Years Ago
Author
Message
Tom Galczynski
Problem Posted 2 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)

Group: Forum Members
Last Active: Last Year
Posts: 29, Visits: 87
Hello.  I am using the RichTextView control and creating a 3 x 2 table with data in the cells. Looks fine in the GUI but when I extract the RTF string from the control, it seems to lose some formatting and when I subsequently load that RTF string to the control, it shows just the first column of the table.  It doesn't matter if I create the table programmatically or in the GUI.  Here is how I am getting the RTF string:
Private Shared _encoding As System.Text.Encoding = System.Text.Encoding.UTF8
...
Public Property Rtf As System.String
   Get
    Dim currentFormat As RichTextEdit.DocumentFormats = Me._format

    Try

      Me.Format = DocumentFormats.Rtf

      Using ms As System.IO.MemoryStream = Me.Stream
       Return _encoding.GetString(ms.ToArray)
      End Using

    Finally

      Me.Format = currentFormat

    End Try
   End Get
   Set(value As System.String)
    Dim currentFormat As RichTextEdit.DocumentFormats = Me._format

    Try

      Me.Format = RichTextEdit.DocumentFormats.Rtf
      Using ms As New System.IO.MemoryStream(_encoding.GetBytes(value))
       Me.Stream = ms
      End Using

    Finally

      Me.Format = currentFormat

    End Try
   End Set
  End Property
Public Property Stream As System.IO.MemoryStream
   Get

    Dim richTextView As Nevron.Nov.Text.NRichTextView = Me._currentView

    If richTextView IsNot Nothing Then
      Dim currentLayout As Nevron.Nov.Text.ENTextLayout = richTextView.Content.Layout
      Try
       richTextView.Content.Layout = Me._currentLayout
       Dim MS As New System.IO.MemoryStream
       richTextView.SaveToStream(MS, Me.DocumentFormat)
       Return MS
      Finally
       richTextView.Content.Layout = currentLayout
      End Try
    End If

    Return Nothing
   End Get
   Set(value As System.IO.MemoryStream)

    If value IsNot Nothing Then

      Dim richTextView As Nevron.Nov.Text.NRichTextView = Me._currentView

      If richTextView IsNot Nothing Then
       richTextView.Content.Sections.Clear()
       richTextView.LoadFromStream(value, Me.DocumentFormat)
       Me._currentLayout = richTextView.Content.Layout

       If Me._navigation = NavigationView.None Then
        'When displaying the plain control, display the contents in web view so scrollbars, etc. work properly.
        richTextView.Content.Layout = Nevron.Nov.Text.ENTextLayout.Web
       End If

      End If

    End If

   End Set
  End Property
...

I realize you can't debug my code in a forum message, but can you point me to areas I need to look at that may affect this? Or point me to any examples (VB.Net) of how to extract the RTF string from the richtextview so it can be saved and retrieved from a database, saved and retrieved from a rtf file?  I have successfully done this with images, text, bolded, fonts, etc. just have troubles with tables.

Thank you very much!
Tom G.





Similar Topics


Reading This Topic