locked
TextBox Top RRS feed

  • Question

  • Hi ..

    How to remove the first LINE in(on The Top) multilineTexbox.I have 100 textbox

    thank 

    Thursday, January 13, 2011 5:20 PM

Answers

  • Hi!

    This would be sufficient to remove first line:

     

    Dim lines As String() = textBox1.Lines.Skip(Of String)(1).Take(textBox1.Lines.Length - 1).ToArray()
    textBox1.Lines = lines

    and this will remove first line from all textboxes: (it will access all textboxes and remove first line)

     

    For Each ctrl As Control In Me.Controls
    If ctrl.[GetType]().Name = "TextBox" AndAlso DirectCast(ctrl, TextBox).Multiline = True Then
    Dim lines As String() = DirectCast(ctrl, TextBox).Lines.Skip(1).Take(textBox1.Lines.Length - 1).ToArray()
    DirectCast(ctrl, TextBox).Lines = lines
    End If
    Next

    *EDIT:

    I wrote it in C# by mistake so converted from an online tool and then paste it here.

    • Proposed as answer by jinzai Friday, January 14, 2011 1:43 AM
    • Marked as answer by mipakteh Friday, January 14, 2011 3:12 PM
    Thursday, January 13, 2011 7:21 PM

All replies

  • Hi!

    This would be sufficient to remove first line:

     

    Dim lines As String() = textBox1.Lines.Skip(Of String)(1).Take(textBox1.Lines.Length - 1).ToArray()
    textBox1.Lines = lines

    and this will remove first line from all textboxes: (it will access all textboxes and remove first line)

     

    For Each ctrl As Control In Me.Controls
    If ctrl.[GetType]().Name = "TextBox" AndAlso DirectCast(ctrl, TextBox).Multiline = True Then
    Dim lines As String() = DirectCast(ctrl, TextBox).Lines.Skip(1).Take(textBox1.Lines.Length - 1).ToArray()
    DirectCast(ctrl, TextBox).Lines = lines
    End If
    Next

    *EDIT:

    I wrote it in C# by mistake so converted from an online tool and then paste it here.

    • Proposed as answer by jinzai Friday, January 14, 2011 1:43 AM
    • Marked as answer by mipakteh Friday, January 14, 2011 3:12 PM
    Thursday, January 13, 2011 7:21 PM
  • I prefer TryCast and List Of for this, but EngrShahan has provided a nice technique to solve your issue...

            For Each ctrl As Control In Me.Controls

                Dim tb As TextBox = TryCast(ctrl, TextBox)

     

                If Not IsNothing(tb) Then

                    If tb.Multiline Then

                        Dim theLines As New List(Of String)

     

                        theLines = tb.Lines.ToList

                        theLines.RemoveAt(0)

                        tb.Lines = theLines.ToArray

                    End If

                    tb.Refresh()

                End If

            Next

     

     

    Friday, January 14, 2011 1:42 AM
  • Hi EngrShahan,

    Thank.

    code work very well.

    But your code remove all in first line and leave a empty line

    how to remove the empty line?

     

    Friday, January 14, 2011 3:12 PM
  • Thank Jinzai........
    Friday, January 14, 2011 3:13 PM
  • Hi!

    My delayed response need some apology. I provided you the tested code and it was working fine. As you said there is something wrong, so checked it again and no change. If your problem is still require any support feel free to share with us.

     

    Regards,

    -Shahan

    Friday, January 14, 2011 3:45 PM