Positioning the text cursor in a TextBox control
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
- for each ...
TextBox1.Text = TextBox1.Text & CStr(...)
next 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
- for each ...
TextBox1.Text = TextBox1.Text & CStr(...)
next 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 ClassThank 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
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.


