0

I want to change value in SelectedText in Infragistics UltraTextEditor before calling Copy method. However, each time I try to set new value, SelectedText becomes blank. I'm working in C#, Visual Studio 2013.

Here is code snippet:

            string textToAlter = this.externalMessageTextBox.SelectedText;

            if (textToAlter.Contains("\r\n"))
                textToAlter = textToAlter.Replace("\r\n", "\r");

            this.externalMessageTextBox.SelectedText = textToAlter;  // SelectedText becomes blank

Additional information:

The text to be copied is an HL7 (Health Level 7) message like the one below. It needs carriage return and new line to make it readable as text in UltraTextEditor, but HL7 standard requires segments to be terminated with with carriage return only. I wanted copied text to be formatted per HL7 standard, because users most commonly copy it for pasting in HL7 specific editor or parser.

Here is the example of text message:

MSH|^~\&|LLS|NI|CTI|TEST0001|199712291047||ORU|57341.002|P|2.2
PID|1|111296|111296||Test^Patient|||M||||||||||1000  
ORC|RE|R6013121-4^CTI|6013121-4^LLS||||||19971229104734  
OBR|1|R6013121-4^CTI|6013121-4^LLS|5763^VITAMIN     B12^L|||19951218000000|||||||19951219091841||||||||19971229104736|||F
HalinaG
  • 1
  • 2
  • what is the text in the textbox can you give an example? Do you have a part of the text selected or the whole text in the textbox? – Nocturnal Dec 30 '14 at 02:20

1 Answers1

0

this has nothing to do with the infragistics control in general

but you have to do it this way even tho i am not quite sure what you are doing...

        string textToAlter = this.externalMessageTextBox.SelectedText;

        if (textToAlter.Contains("\\r\\n"))
            textToAlter = textToAlter.Replace("\\r\\n", "\\r");

        this.externalMessageTextBox.SelectedText = textToAlter;

lets say the .text in the Textbox is "abc\r\n" the outcome would be

"abc\r"

Nocturnal
  • 386
  • 2
  • 8
  • Actually I do not have problem with text formatting. The characters are replaced just fine. I can change text itself without a problem, but not selected text. Even if I want to set selected text to something simple like "This is a test", it won't let me do it. – HalinaG Dec 30 '14 at 16:24
  • your code is working fine for me i have to select the text and it replaces it, but i had to double the char "\" to "\\" in order to get it working – Nocturnal Dec 31 '14 at 02:01