以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]保存前验证所有 TextBox 不能为空白  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=70691)

--  作者:wangyinming
--  发布时间:2015/6/26 15:04:00
--  [求助]保存前验证所有 TextBox 不能为空白
保存前验证所有 TextBox 不能为空白,
代码怎么写?

If e.Form.Controls("工号").Text = "" Then
    MessageBox.Show("工号不能为空")
    Return
End If

这样一个一个太麻烦了。

--  作者:Bin
--  发布时间:2015/6/26 15:05:00
--  
For Each c As WinForm.Control In e.Form.Controls
    If
 Typeof c Is WinForm.TextBox Then \'判断是否是文本框
        
Dim t As WinForm.TextBox = c \'使用特定类型的变量引用
          if t.text = "" then
       e.cancel=true
       return
     end if
  End
 If
Next