VB.NET 不同范围的嵌套 With 语句
我想知道这是否可能。我有一个列表表(lstTable),它与我试图用公共结构(ELEM_DATA)中的信息填写的表单相同。我知道如果嵌套 with 语句在同一范围内,则它会起作用,但是我如何使用下面的示例 2 来执行此操作:
示例 1:
With me.lstTable.Items(RECORD)
.SubItems(1).text = ELEM_DATA(RECORD).name
.SubItems(2).text = ELEM_DATA(RECORD).number
end with
示例 2:
With me.lstTable.Items(RECORD)
With ELEM_DATA(RECORD)
.SubItems(1).text = .name
.SubItems(2).text = .number
end with
end with
我不知道是否可能,或者是否像更改 (.name 一样简单) )到别的东西。
I am wondering if this is possible. I have a List Table (lstTable) that is on the same form that I am trying to fill in with information from a public structure (ELEM_DATA). I understand nested with statements will work if it is within the same scope but how can I do this with example 2 below:
Example 1:
With me.lstTable.Items(RECORD)
.SubItems(1).text = ELEM_DATA(RECORD).name
.SubItems(2).text = ELEM_DATA(RECORD).number
end with
Example 2:
With me.lstTable.Items(RECORD)
With ELEM_DATA(RECORD)
.SubItems(1).text = .name
.SubItems(2).text = .number
end with
end with
I didnt know if it is possible or if it would be as simple as changing (.name) to something else.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
嵌套 With 语句有效(请参阅有关冲突的评论)。不幸的是,您不能在内部成员中使用外部成员。但是由于您的外部WITH是引用类型,您可以使用局部变量来“别名”它,正如您在评论中所建议的那样。
下面的链接展示了如何使用嵌套的WITH语句。
http://ideone.com/agjne
Nested With statements work (see comment about conflicts). Unfortunately you can't use the outer members inside the inner with. But since your outer WITH is a refernce type you could use a local variable to "alias" it as you suggest in you comment.
Here's a link to show how nested WITH statements can used.
http://ideone.com/agjne