Search code examples
wpfvb.nettextboxmultiline

How to change text of specific line in multiline textbox in WPF?


I have a multi-line text box in my WPF project, and I want to change the specified line text. I used to do this easily in Win form, but there is no Lines option in WPF Text box. For example, I used to do this in Windows Form:

Dim lines As String() = VTextBox1.Lines

            lines(Specific Line Number) = "This is a test."

            VTextBox1.Lines = lines

But this piece of cod, not working in WPF textbox.

Do I have any chance that I do this in the WPF textbox?

I have no idea how to do that.


Solution

  • Do it "manually" by manipulating the string yourself:

    Dim lines As String() = VTextBox1.Text.Split(vbLf)
    
    Dim lineNumber As Integer = 5
    If lines.Length > lineNumber Then
        lines(lineNumber) = "This is a test."
        VTextBox1.Text = String.Join(vbLf, lines)
    End If