使用变量访问控件

huangapple go评论64阅读模式
英文:

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"

huangapple
  • 本文由 发表于 2023年6月26日 15:45:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/76554563.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定