1. Rodolfo Reyes
  2. PowerBuilder
  3. Tuesday, 23 November 2021 18:20 PM UTC

Hi,

 

I want to place plain text inside a Rich Text control.

 

I have been trying in many ways, but I can't. When executing the code it does not give errors, but it does not work.

 

This is with PowerBuilder 2019 R2

 

String ls_richtext = "plain text"


// Prevent flicker
 rte_texto_xml.SetRedraw(FALSE)

// Replace the old text with text for the current row
 rte_texto_xml.SelectTextAll()
 rte_texto_xml.Clear()


 rte_texto_xml.PasteRTF(ls_richtext)

  rte_texto_xml.SetRedraw(TRUE)

 

Will anyone have an example that they can give me?

 

Thanks in advance,

 

Accepted Answer
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Wednesday, 24 November 2021 03:10 AM UTC
  2. PowerBuilder
  3. # Permalink

PasteRTF() is for pasting text which is formatted as RTF. If you want to paste plain text, you have to use the Paste() function. Before the Paste() function would work, you have to put the text on the clipboard. Another easier way, would be to use the ReplaceText (string ) function.

Also your comment is incorrect: // Replace the old text with text for the current row

SelectTextAll() selects all text of all "rows", not just the "current row". ("line" is a more appropiate term when speaking of a RT control).

If you have "all text selected" and after that are going to do a Paste() or ReplaceText(....), then there's no need to call the Clear() function first.

2019 R2 might have some bugs with certain Richtext functions. Maybe upgrading will improve things, though you'll probably find new bugs, so not sure if that's really good advice if you have a lot of existing code.

 

Try this:

String ls_PlainText = "plain text"


// Prevent flicker (try first without changing the setredraw. If it works, then uncomment this next line).
//rte_texto_xml.SetRedraw(FALSE)

// make sure the control is enabled:
rte_texto_xml.enabled = true
rte_text_xml.displayOnly = false

// Replace the old text with text for the current row
rte_texto_xml.SelectTextAll()

rte_texto_xml.ReplaceText(ls_PlainText)

rte_texto_xml.SetRedraw(TRUE)

regards.

Comment
  1. Miguel Leeuwe
  2. Wednesday, 24 November 2021 03:17 AM UTC
Another thing: try first without setting setredraw() to false (you never know).

Also, make sure that your rte is enabled and that it's not set to "display only" (though that last one only became a bug in 2019 R3).
  1. Helpful
  1. Rodolfo Reyes
  2. Thursday, 25 November 2021 23:17 PM UTC
Thank you very much Miguel Leeuwe . It worked perfectly.
  1. Helpful
  1. Miguel Leeuwe
  2. Friday, 26 November 2021 00:28 AM UTC
Great!
  1. Helpful
There are no comments made yet.


There are replies in this question but you are not allowed to view the replies from this question.