以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  遍历控件求助  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=80849)

--  作者:xujie80
--  发布时间:2016/2/3 19:48:00
--  遍历控件求助
我在一个窗口中设计录入界面,想遍历窗口中的所有控件,如果有空值,则返回提示 
For Each c As WinForm.Control In e.Form.Controls
    If e.form.controls(c).value Is Nothing Then
        MessageBox.show("对不起,数据输入不完整,请补充输入")
    Else
        e.Form().Close
    End If
Next

但在执行过程中提示:
类型“winform.control"的值无法转换为”string"

请问如何解决
图片点击可在新窗口打开查看
图片点击可在新窗口打开查看

--  作者:大红袍
--  发布时间:2016/2/3 19:56:00
--  
For Each c As Object In e.Form.Controls
    If c.text Is Nothing Then
        MessageBox.show("对不起,数据输入不完整,请补充输入")
    Else
        e.Form.Close
    End If
Next
--  作者:xujie80
--  发布时间:2016/2/3 21:06:00
--  
红袍先生:上述语句不起作用,有空值也不出现提示,直接ELSE以后了
--  作者:大红袍
--  发布时间:2016/2/3 21:22:00
--  
Dim flag As Boolean = True
For Each c As Object In e.Form.Controls
    If c.text Is Nothing Then
        MessageBox.show("对不起,数据输入不完整,请补充输入")
        flag = False
    End If
Next
If flag Then
    e.Form.Close
End If

--  作者:xujie80
--  发布时间:2016/2/3 22:15:00
--  
还是不行,我只好定义一个数组,把控件全放进去再处理了,希望红袍大师指点迷津
--  作者:大红袍
--  发布时间:2016/2/3 22:26:00
--  

试试

 

Dim flag As Boolean = True
For Each c As Object In e.Form.Controls
    If Typeof c Is winform.Textbox OrElse Typeof c Is winform.ComboBox Then
        If c.text Is Nothing Then
            MessageBox.show("对不起,数据输入不完整,请补充输入")
            flag = False
        End If
    End If
Next
If flag Then
    e.Form.Close
End If

 

再不行,做个例子上来上来测试


--  作者:xujie80
--  发布时间:2016/2/3 23:01:00
--  
例子
 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:管理项目1.zip


--  作者:大红袍
--  发布时间:2016/2/3 23:04:00
--  
Dim flag As Boolean = True
For Each c As Object In e.Form.Controls
    If Typeof c Is winform.Textbox OrElse Typeof c Is winform.ComboBox Then
        If c.text = Nothing Then
            MessageBox.show("对不起,数据输入不完整,请补充输入")
            flag = False
            Exit For
        End If
    End If
Next
If flag Then
    e.Form.Close
End If

--  作者:xujie80
--  发布时间:2016/2/3 23:59:00
--  
行了,先要判断类型?
--  作者:大红袍
--  发布时间:2016/2/4 9:21:00
--  
以下是引用xujie80在2016/2/3 23:59:00的发言:
行了,先要判断类型?

 

不是,不能用 Is Nothing,要用 = Nothing 才行。