以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  遍历所有控件,清空控件的内容  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=81617)

--  作者:fubblyc
--  发布时间:2016/3/2 10:50:00
--  遍历所有控件,清空控件的内容

嘿嘿,有没有什么办法可以遍历所有控件,然后清空他的内容的?不然要一个一个地写。。。有时候删掉控件,忘了删对应的代码还会报错。。。


图片点击可在新窗口打开查看此主题相关图片如下:9.png
图片点击可在新窗口打开查看

--  作者:大红袍
--  发布时间:2016/3/2 10:55:00
--  

 遍历 panel 容器里面的控件

 

For Each c As Object In e.Form.controls("panel1").children
   
    If typeof c Is winform.TextBox OrElse typeof c Is winform.DateTimePicker  Then
       
        c.text = Nothing
       
    End If
   
Next


--  作者:fubblyc
--  发布时间:2016/3/2 21:16:00
--  

未找到类型“SplitContainer”的公共成员“children”。

大红袍老师,我的容器是 SplitContainer ,

我写成这样。。。For Each c As Object In e.Form.controls("SplitContainer2").children

 

然后就报错了。。。


--  作者:大红袍
--  发布时间:2016/3/2 21:19:00
--  

For Each c As Object In e.Form.controls("SplitContainer2").panel1.children

 

For Each c As Object In e.Form.controls("SplitContainer2").panel2.children



--  作者:fubblyc
--  发布时间:2016/3/2 21:28:00
--  

没有反应,大红袍老师。。。

For Each c As Object In e.Form.controls("SplitContainer2").panel1.children  
    If typeof c Is winform.TextBox OrElse typeof c Is winform.DateTimePicker OrElse typeof c Is winform.CheckedComboBox Then       
        c.text = Nothing       
    End If   
Next

For Each c As Object In e.Form.controls("SplitContainer2").panel2.children  
    If typeof c Is winform.TextBox OrElse typeof c Is winform.DateTimePicker OrElse typeof c Is winform.CheckedComboBox Then       
        c.text = Nothing       
    End If   
Next


--  作者:fubblyc
--  发布时间:2016/3/2 21:34:00
--  
就是我在 textbox 上写东西,点按钮,都没有清空
--  作者:大红袍
--  发布时间:2016/3/2 21:36:00
--  
加入msgbox弹出c.name