I'm trying to get the text from a TextBox but the following is always returned:
"System.Windows.Forms.TextBox, Text: "
and then the actual desired text in the control is shown after "Text:".
How can I get just the text in the control without having to use String operations to cut that useless part off?

1 answers
It sounds like you're doing something like:
textBox1.ToString()
What you want is:
textBox1.Text
answered 2 years ago by:
17279
I'm using the Text property. Here's my line of code:
String myConnStr = (txtEdt_connection.Text);
and just for fun, I tried .ToString() as well. It also returned something similar: "System.Windows.FOrms.TextBox, Text: ..."
answered 2 years ago by:
15
How did you set the Text property in the first place, programatically or by typing it into the textbox?
If the former, what code did you use?
answered 2 years ago by:
17279
First, I tried setting it in the Properties pane that's available within Visual C#'s Design view.
Then, I tried setting it in the actual ProjectName.Designer.cs file where everything is initialized, using this line:
this.txtEdt_connection.Text = "-no connection specified-";
answered 2 years ago by:
15
And if you then do:
MessageBox.Show(txtEdt_connection.Text);
it displays:
System.Windows.Forms.TextBox, Text: -no connection specified-
If that's the case, I'm completely baffled!
Time I packed in for the day, I think :)
answered 2 years ago by:
17279
Actually, I then do:
txtEdt_connection.Text = txtEdt_connection + "Rawrawrawr";
so that the control displays the old string and my (obviously elegant) distinction at the end.
I'm baffled too! Thanks for trying, Vulpes. :)
answered 2 years ago by:
15
Ah, I think I've spotted now where the problem lies!
When you do this:
txtEdt_connection.Text = txtEdt_connection + "Rawrawrawr";
the ToString() method is called implicitly on txtEditConnection and the result is then concatenated with "Rawrawrawr".
If you do it like this instead then the problem should go away:
txtEdt_connection.Text += "Rawrawrawr";
answered 2 years ago by:
17279
Good to know! Thanks, Vulpes!
answered 2 years ago by:
15
This post was imported from csharpfriends, if you have a similiar question please ask it again.
All previous members have been migrated, hope you enjoy the new platform!