tags:

views:

27

answers:

3

hello, i need to add an text at the end of the cursor position in vb .net i tried

 TextBox1.Text = TextBox1.Text.Insert(TextBox1.SelectionStart, "<br>")

it works but the cursor position sets to starting position

A: 

Just re-set the SelectionStart property after assigning the text:

Dim insertText = "<br>"
Dim insertPos As Integer = TextBox1.SelectionStart
TextBox1.Text = TextBox1.Text.Insert(insertPos, insertText)
TextBox1.SelectionStart = insertPos + insertText.Length
Konrad Rudolph
A: 

Add this code after your code to move the caret to the end of your textbox value:

TextBox1.SelectionStart = TextBox1.TextLength
Lee Sy En
A: 

Hello everybody, my name is Julio Cesar P. Magalhaes, live in Brazil, this tip was very good. Thank you.

Julio Cesar P. Magalhaes