Visual Basic > Visual Basic Forums > Visual Basic Language > Positioning the text cursor in a TextBox control
Ask a questionAsk a question
 

AnswerPositioning the text cursor in a TextBox control

  • Wednesday, June 21, 2006 1:36 AMB Langston Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hello

    I have a routine that iterates thru a collection and I want to print each iteration into a TextBox without having the second iteration overprint the first and so on. How do I position the text cursor between each iteration thru the 'For Each' that I am using?

    Thank you

Answers

  • Wednesday, June 21, 2006 1:39 AMnobugzMVP, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    for each ...
      TextBox1.Text = TextBox1.Text & CStr(...)
    next

  • Wednesday, June 21, 2006 2:11 AMspotty Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Public Class Form1

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

            '//Simply Setting the Control Property
            For Each c As Control In Controls
                TextBox1.Text = TextBox1.Text & c.Name.ToString & vbCrLf
            Next


            '//using a string variable and setting the property only at the end
            Dim s As String = ""
            For Each c As Control In Controls
                s = s & c.Name.ToString & vbCrLf
            Next
            TextBox1.Text = s
        End Sub
    End Class

All Replies

  • Wednesday, June 21, 2006 1:39 AMnobugzMVP, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    for each ...
      TextBox1.Text = TextBox1.Text & CStr(...)
    next

  • Wednesday, June 21, 2006 2:11 AMspotty Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Public Class Form1

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

            '//Simply Setting the Control Property
            For Each c As Control In Controls
                TextBox1.Text = TextBox1.Text & c.Name.ToString & vbCrLf
            Next


            '//using a string variable and setting the property only at the end
            Dim s As String = ""
            For Each c As Control In Controls
                s = s & c.Name.ToString & vbCrLf
            Next
            TextBox1.Text = s
        End Sub
    End Class

  • Wednesday, June 21, 2006 2:21 AMB Langston Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Thank you very much.

    You and the coder that answered me before you (nobugz) have both given me the answer to my admittedly basic question.

    I only wish Microsoft in providing their literal *mountain* of help with Visual Studio 2005 could make it easier for a newby to get real basic help. Heck, the pros could easily skip that stuff but new learners can get stumped on the most basic of things.

    Thanks again, to both of you.

    Bill Langston

  • Friday, November 06, 2009 3:27 PMsojour Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    I think it should be noted that -
     '//Simply Setting the Control Property
            For Each c As Control In Controls
                TextBox1.Text = TextBox1.Text & c.Name.ToString & vbCrLf
            Next
    will repeat the cursor within button1 sub if button clicked and -
     '//using a string variable and setting the property only at the end
            Dim s As String = ""
            For Each c As Control In Controls
                s = s & c.Name.ToString & vbCrLf
            Next
            TextBox1.Text = s

    will not.