| | |
C# Find and Relate to Runtime Textbox
Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: May 2009
Posts: 78
Reputation:
Solved Threads: 0
Hi. I'm new to c# and have ran into a problem, I am using the following code to generate textboxes within a panel.
This also caps the textboxes to a maximum of 10, this code works fine for me it is the next bit that I am stuck on. I need to store values entered into each one of the textbox into diffrent variables which I can't do correctly, I am using the following code to find the textbox control.
I think this is were I have gone wrong and I need help please.
C# Syntax (Toggle Plain Text)
private void button1_Click(object sender, EventArgs e) { AddFields(); } private void AddFields() { if (textBoxIndex != 10) { TextBox field = new TextBox(); field.Name = "field" + textBoxIndex.ToString(); textBoxIndex++; field.Size = new Size(200, 20); panel1.Controls.Add(field); } else { MessageBox.Show("A Maximum of 10 Areas is Supported"); }
C# Syntax (Toggle Plain Text)
if (textBoxIndex != 1) { } else { Control[] ctrls = Controls.Find("field1", false); for (int i = 0; i < ctrls.Length; i++) { TextBox field1 = (TextBox)ctrls[0]; field1.Text = Variable1; field1.Text = ""; } }
I think this is were I have gone wrong and I need help please.
•
•
Join Date: May 2009
Posts: 78
Reputation:
Solved Threads: 0
Thanks, it now looks like this.
do my if statements look ok, I wasn't sure whether to go != or == I think what I've got is wrong because it's still not working with panel1.Controls.Find.
C# Syntax (Toggle Plain Text)
private void FieldStore() { if (textBoxIndex != 1) { } else { Control[] ctrls = panel1.Controls.Find("field1", false); for (int i = 0; i < ctrls.Length; i++) { TextBox field1 = (TextBox)ctrls[0]; field1.Text = Area.Room1; field1.Text = ""; } } }
do my if statements look ok, I wasn't sure whether to go != or == I think what I've got is wrong because it's still not working with panel1.Controls.Find.
You don't have to define an array of controls here. You have them ready in your panel1 Controls collection.
Perhaps you should use something like this (I have not tested it, I leave that to you)
Also the last two statements look wierd. You assign a value to Text and then you make Text empty...
Perhaps you should use something like this (I have not tested it, I leave that to you)
c# Syntax (Toggle Plain Text)
string Tboxname = string.Empty(); for (int i = 0; i < Numberoftextboxes; i++) { Tboxname = "field" + i.ToString(); TextBox field1 = panel1.Controls.Find(Tboxname, false); field1.Text = Area.Room1; field1.Text = ""; }
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Make love, no war. Cave ab homine unius libri.
Danny
C# Syntax (Toggle Plain Text)
foreach(Control c in Panel1.Controls) { if(c is TextBox) MessageBox.Show(string.Format("TextBox Name: {0} , TextBox Text {1}",c.Name, c.Text)); }
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
You're welcome my friend, Danny
I Hope it solves their problem.
I Hope it solves their problem.
Last edited by Ramy Mahrous; Jul 18th, 2009 at 8:01 am.
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
If you know anything about it. Its Text or its Name you can add a condition
C# Syntax (Toggle Plain Text)
foreach(Control c in Panel1.Controls) { if(c is TextBox) if(c.Name = "field1") //or any property c.Text = "" or c..... MessageBox.Show(string.Format("TextBox Name: {0} , TextBox Text {1}",c.Name, c.Text)); }
Last edited by Ramy Mahrous; Jul 18th, 2009 at 8:33 am.
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
![]() |
Similar Threads
- "Find next" dialog for textbox (VB.NET)
- 4 Function Calculator textbox or field control (ASP.NET)
- datagrid find record code - what's wrong?? (VB.NET)
- Runtime (Java)
- Printing a textbox? (C#)
Other Threads in the C# Forum
- Previous Thread: Replace the Contents of the Array
- Next Thread: HOW To Setup Project with SQL?
| Thread Tools | Search this Thread |
Tag cloud for C#
.net access ado.net algorithm array barchart bitmap box broadcast buttons c# chat check checkbox class client color combobox control conversion csharp custom database datagrid datagridview dataset datetime degrees development draganddrop drawing encryption enum event excel file form format forms ftp function gdi+ httpwebrequest image index input install java label list listbox listener login mandelbrot math mouseclick mysql networking object operator oracle path photoshop picturebox pixelinversion post prime programming radians regex remote remoting resource richtextbox save saving serialization server sleep socket sql statistics string table text textbox thread time timer treeview update usercontrol validation view visualstudio webbrowser windows winforms wpf xml






