清除多个文本框时出错 [英] getting error while clearing multiple textboxes

查看:85
本文介绍了清除多个文本框时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好



i使用下面的代码清除表单中的多个文本框但是我收到错误。请告诉我问题



 私有  Sub  ClearTextBoxes(< span class =code-keyword> ByVal  depObject  As  DependencyObject)
对于 i 作为 整数 = 0 VisualTreeHelper.GetChildrenCount(depObject) - 1
如果 TypeOf depObject TextBox 然后
CType (depObject,TextBox).Text = Nothing
结束 如果

ClearTextBoxes(VisualTreeHelper.GetChild(depObject,i))
下一页





我得到的错误是:



错误4'System.Windows.DependencyObject'类型的表达式永远不能是'System.Windows.Forms.TextBox'类型。 

解决方案

您似乎使用了错误的命名空间 TextBox class。



请尝试 System.Windows.Controls .TextBox


Hi all

i used the below code to clear multiple textbox in a form but i am getting error.please tell me the problem

Private Sub ClearTextBoxes(ByVal depObject As DependencyObject)
       For i As Integer = 0 To VisualTreeHelper.GetChildrenCount(depObject) - 1
         If TypeOf depObject Is TextBox Then
               CType(depObject, TextBox).Text = Nothing
          End If

         ClearTextBoxes(VisualTreeHelper.GetChild(depObject, i))
       Next



Error i am getting is:

Error	4	Expression of type 'System.Windows.DependencyObject' can never be of type 'System.Windows.Forms.TextBox'.	

解决方案

It seems like you use the wrong namespace for the TextBox class.


Try System.Windows.Controls.TextBox instead.


这篇关于清除多个文本框时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆