专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > VB Dotnet

递归地按照Name属性查找控件,为什么找不到?该如何处理

发布时间:2011-06-23 16:04:16 文章来源:www.iduyao.cn 采编人员:星星草
递归地按照Name属性查找控件,为什么找不到?
问题是老生常谈了,但是到自己写就傻眼了。

比如查找一个叫做“txtAAA”的文本框,txtAAAz在GroupBox1里,容器间的关系是这样的:
Form---〉TabControl---〉TabPage---〉GroupBox1,按照搜索引擎的思路,写了一个函数:

VB.NET code
Private Function FindControlRecursive(ByVal iCon As Control, ByVal iName As String)
        If iCon.Name = iName Then
            Return iCon
        End If
        For Each iChild As Control In iCon.Controls
            Dim foundcontrol As Control = FindControlRecursive(iChild, iName)
            If foundcontrol IsNot Nothing Then
                Return foundcontrol
                MsgBox("!")
            End If
        Next
        Return Nothing
    End Function


试验了一下,最后返回的还是Nothing,请问这个函数哪里需要改正?
谢谢大家的回答!

------解决方案--------------------
你都Return Nothing,肯定返回Nothing
------解决方案--------------------
Debug.Print(FindControlRecursive(Me, Me.CheckBox1.Name).Name)
没有问题
------解决方案--------------------
搞错,
return nothing 不能要
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: