Insert text into WPF textbox at caret position?

To simply insert text at the caret position: textBox. Text = textBox.Text. Insert(textBox.

CaretIndex, "") To replace the selected text with new text: textBox. SelectedText = "CaretIndex); textBox. ScrollToLine(lineIndex).

To simply insert text at the caret position: textBox. Text = textBox.Text. Insert(textBox.

CaretIndex, ""); To replace the selected text with new text: textBox. SelectedText = ""; To scroll the textbox to the caret position: int lineIndex = textBox. GetLineIndexFromCharacterIndex(textBox.

CaretIndex); textBox. ScrollToLine(lineIndex).

If you want to move the caret after the inserted text the following code is useful textBox. SelectedText = "New Text"; textBox. CaretIndex += textBox.SelectedText.

Length; textBox. SelectionLength = 0.

I found an even more simple solution by myself: textBox. SelectedText = "New Text"; textBox. SelectionLength = 0; Then scroll to the position as stated by Tarsier.

TextBox does not have a SelectedIndex property. I assume you meant SelectedText, and, yes, you're right, it is simpler. – Tarsier Jan 22 '10 at 15:49 Yes, I did mean SelectedText.

I changed it in my answer above. – Roice Jan 25 '10 at 9:42.

Use TextBox. CaretIndex to modify the text bound to the TextBox. Text property.

– Roice Jan 22 '10 at 12:58 Actually this IS a very simple way. – Thorsten79 Jan 22 '10 at 13:15 But you did not consider my other needs: How can it be replaced by the new text? And how can I make that the caret scrolls into view?

– Roice Jan 22 '10 at 14:25 Tarsier has answered all that. – Thorsten79 Jan 22 '10 at 15:07.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions