英文:
Using Variables to access controls
问题
我试图在VB.NET中使用变量名引用一些文本框,就像
Me.Controls("myfield" & xx).Text = "一些文本"
但是我一直收到错误消息,似乎无法正确引用控件。任何帮助将不胜感激。
我已经尝试了在该网站上找到的其他解决方案,例如首先搜索该字段,然后尝试填充它,但仍然收到错误消息。
我得到的错误是
System.NullReferenceException '对象引用未设置为对象的实例。'
英文:
I am trying to reference some text boxes in VB.NET using variable names, like
Me.Controls("myfield" & xx).Text = "some text"
However I keep getting errors and can't seem to work out how to reference the controls correctly this way. Any help would be most appreciated.
Have tried other solutions found within this site, such as searching for the field first and then trying to populate it, but still get errors.
The error I am getting is
> System.NullReferenceException 'object reference not set to an instance
> of an object'
答案1
得分: 1
"Discovered that because the controls are in a group box, you have to reference the group box first, then the control. Like me.groupboxname.controls("myfield" & (xx).tostring).Text = "Some Text""
"发现因为控件在一个分组框中,您必须首先引用分组框,然后再引用控件。像这样:me.groupboxname.controls("myfield" & (xx).tostring).Text = "一些文本""
英文:
Discovered that because the controls are in a group box, you have to reference the group box first, then the control. Like me.groupboxname.controls("myfield" & (xx).tostring).Text = "Some Text"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论