如何创建文本框数组并访问它们? [英] How to create array of textboxes and access to them?

查看:125
本文介绍了如何创建文本框数组并访问它们?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的表单中有很多TextBox,需要使用For i = 0等来更改它们的文本。

我从(从某处找到)开始

  Dim  arrText  As   ArrayList 
arrText.Add(_Text1_0)
arrText.Add(_Text1_1)
arrText.Add(_Text1_2)
arrText.Add(_Text1_3)



但这是错误的方向,因为我无法访问TextBoxes。

请帮助。

解决方案

您好,



Windows窗体类和ASP.Net Page类都有Controls集合。您可以枚举此内容以查找文本框。以下MSDN文档中可以找到更多帮助



问候,


Quote:

但这是错误的方向,因为我无法访问TextBoxes。

不在方向。可能你执行这个建议很糟糕。请检查(或在此处发布)您的实际代码。



解决方案1 ​​,也很好。此外,文档提供了有用的示例,您只需要成为一个更仔细的读者。


  Dim  Ctr() As  Control = {_ Text1_0,_Text1_1,_Text1_2,_Text1_3,_Text1_4,_Text1_5} 

< span class =code-keyword>对于 i = 0 Ctr.Length - 1
Ctr(i).Text = 来自FOR的文字
下一页



很难找到它。


I have a lot of TextBoxes in my form and need to change Text of them using For i = 0... etc.
I started from(found somewhere)

Dim arrText As New ArrayList
arrText.Add(_Text1_0)
arrText.Add(_Text1_1)
arrText.Add(_Text1_2)
arrText.Add(_Text1_3)


But it's wrong direction, because I can't access to TextBoxes.
Please help.

解决方案

Hello,

Both Windows Form Class and ASP.Net Page class have Controls collection. You can enumerate this to find your text boxes. More help can be found in following MSDN documents

Regards,


Quote:

But it's wrong direction, because I can't access to TextBoxes.

No that is in a good direction. Probably you are bad implementing the suggestion. Please check (or post here) your actual code.

Solution 1, also, is good. Moreover documentation do provide useful examples, you have just to be a more careful reader.


Dim Ctr() As Control = {_Text1_0, _Text1_1, _Text1_2, _Text1_3, _Text1_4, _Text1_5}

For i = 0 To Ctr.Length - 1
    Ctr(i).Text = "Text from FOR"
Next


Was hard to find it.


这篇关于如何创建文本框数组并访问它们?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆