|
|
Ok, I think I´ve explained it wrong. (Please correct me if I make mistakes with my englisch).
I have a string called 'str'. In this string is one part of a Command. str = "textBox12".
Now, I must read the textBox12. Str says to me, which textBox I must read. In this textBox12 is an integer=12 (for example)
So I want a command like:
int a = ConvertToInt16(str.Text)
str.Text stands for textBox12.Text
I hope I´ve explained it better.
|
|
|
|
|
Ah.- Iterate through the form's
Controls collection to get at the named control.
- Use Int16.TryParse() to convert the
.Text property of that control to an integer. /ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
This is what I had in mind. But I thouhgt there is a simpler way. But ok, I will try it.
|
|
|
|
|
How I can iterate through the forms collection?
|
|
|
|
|
|
so simple? I will work on it and try to solve my Problem.
I'am very pleased how fast the members answer!
|
|
|
|
|
ok, it doesn´t work. I´ve got the error, that I need an object reference for form1.controls.
Can you explain it with other words please?
|
|
|
|
|
string lookForControl = "textBox12";
string foundControlText = "";
foreach(Control ctrl in this.Controls)
{
if(ctrl.Name == lookForControl)
{
foundControlText = ctrl.Text;
}
}
MessageBox.Show("Control " + lookForControl + " has the Text: " + foundControlText);
---
How to get answers to your questions[^]
-- modified at 9:48 Thursday 20th July, 2006
|
|
|
|
|
That code won't work if the target control is in the Controls collection of a container, such as a GroupBox or Panel. You should make a recursive method which iterates ControlCollections searching for a control with the specified name.
An easier way to do this would be to use reflection to get the control by it's name, assuming that the control is not created dynamically. For example:
FieldInfo fi = this.GetType().GetField( "textBoxInfinity", BindingFlags.Instance | BindingFlags.NonPublic );
TextBox txt = fi.GetValue( this ) as TextBox;
txt.Text = "HELLO";
:josh:
My WPF Blog[^]
|
|
|
|
|
You´re right. I noticed it, because my textBoxes were in GroupBoxes .
Reflections...aha....I must read about it, I didn´t heared about reflections. (is this right -> grammar?)
Thanks to you both!
|
|
|
|
|
Schimaera wrote: I didn´t heared about reflections. (is this right -> grammar?)
No, it would be better to say "I had not heard of reflection."
:josh:
My WPF Blog[^]
|
|
|
|
|
|
Totally agree Josh, but as the OP seemed confused already I thought starting simple was the best way to go.
Had the poster come back and said "It does not work because textbox12 is inside a panel", then I would have delved into the obvious recursive method!
---
How to get answers to your questions[^]
|
|
|
|
|
very thoughtful
|
|
|
|
|
J4amieC wrote:
Had the poster come back and said "It does not work because textbox12 is inside a panel", then I would have delved into the obvious recursive method!
My concern was that the OP's confusion might indicate that he/she wouldn't necessarily make the connection between the fact that the TextBox was in a GroupBox and the fact that the provided method did not work as provided.
:josh:
My WPF Blog[^]
|
|
|
|
|
Oh...it was my first thouhgt. I reallized that all Boxes around were detected only. So I tested it without a groupBox and voila it works.
|
|
|
|
|
Thank you very very much! I realized, that I must learn more about this stupid "this"
|
|
|
|
|
Schimaera wrote: Command. str = "textBox12".
shouldn't it be textBox12.Text
and
Schimaera wrote: int a = ConvertToInt16(str.Text)
int a = ConvertToInt16(str)
Best Regards,
Apurva Kaushal
|
|
|
|
|
1. int.Parse(textBox12.Text);
2. Convert.ToInt32(textBox12.Text);
|
|
|
|
|
You forget the .Text property
textBox12.Text
Eran Aharonovich (eran.aharonovich@gmail.com )
Noviway
|
|
|
|
|
I want to use Global Variable concept in C#.NET Project
for information sharing between forms pages.
Please help me how to do it ?
|
|
|
|
|
Store that data in a class and pass an instance (i.e. the same instance) of that class to each form. You may want to consider using a singleton pattern[^].
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
Hi
How can I access a PHP web service in C#.NET 2003
Thanks
Jyotsna
|
|
|
|
|
I got the answer
Thanks anyways
~jyo
|
|
|
|