Carot Position in a TextBox

Hi all!

I'm having a bit of a problem with a textbox - I need to get the position of the caret in a textbox called TextBox1. The reason for the above is that I want to insert some text at this position. I've tried everything I could think of, so I'd appreciate any help.

Thanks in advance!

Johannes





Answer this question

Carot Position in a TextBox

  • Sequel2k5

    Me.TextBox1.SelectionStart



  • TJ_1

    Thanks! That did the trick !

    Johannes


  • dtrickett

    Hi,

    TextBox1.SelectedText = "this"

    --
    SvenC


  • Simone1

    Hi

    Thanks for your reply, however, I'm still having problems. I've tried the TextBox1.Text.Insert(Me.TextBox1.SelectionStart, "this") to insert the text at the carot's position, but that does not insert the text.

    Any suggestions

    Johannes


  • pccoder

    Sven's code is shorter and probably what you want.

    But to make your original code work, you could have

    said:

    TextBox1.Text = TextBox1.Text.Insert(TextBox1.SelectionStart, "test")

    which would do an insert even if some text is selected.

    Sven's code will do an overwrite if there is selected text.

    Which again, is probably what you wanted anyway.



  • Carot Position in a TextBox