本文介绍了如何从动态创建的textBoxs中获取数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了textBoxs,所以

I create textBoxs so

for(int i = 0; i < amount_restriction; i++)
            {
                left = 40;
                for (int j = 0; j < amount_variables; j++)
                {
                    var textBox = new TextBox();
                    textBox.Width = 30;
                    textBox.Top = 150 + top;
                    textBox.Left = left;
                    Controls.Add(textBox);
                    left += 50;
                }
                var combobox = new ComboBox();
                combobox.Items.Add("=");
                combobox.Items.Add("<=");
                combobox.Items.Add(">=");
                combobox.Width = 40;
                combobox.Top = 150 + top;
                combobox.Left = left;
                Controls.Add(combobox);
                left += 60;

                var textBox1 = new TextBox();
                textBox1.Width = 30;
                textBox1.Top = 150 + top;
                textBox1.Left = left;
                Controls.Add(textBox1);

                top += 40;
                
            }




告诉我如何在这些textBoxs中输入数据


Tell me how I can get the data entered in these textBoxs

推荐答案

您可以为每个TextBox指定一个名称/ ID,并使用它的名称/ ID可以找到你想要的特定TextBox。

You could give a Name/ID to each of your TextBox, and use its name/ID to find the specific TextBox you want.

//Give the name/ID the the TextBox
var textBox = new TextBox();
textBox.Name = "txtBox1"
textBox.ID = "textBox1"

//Get the TextBox by name/ID
TextBox txtBox1 = (TextBox)Controls["txtBox1"];

TextBox textBox1 = (TextBox)FindControl("textBox1");

或者,您还可以将TextBox控件保存为数组引用,然后将它们分别取出。

Or, you could also keep your TextBox controls into an array as a reference, then get each of them out.

// Defined at the Form level
private TextBox[] textBoxes = new TextBox[20];

...

// Store the reference in your loop
var t = new TextBox();
textBoxes[j] = t;

希望这会对您有所帮助。

Hope this will be helpful to you.


这篇关于如何从动态创建的textBoxs中获取数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 10:20