Click here to Skip to main content
15,880,725 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all

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

VB
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'.	
Posted

1 solution

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


Try System.Windows.Controls.TextBox instead.

 
Share this answer
 
Comments
[no name] 7-May-13 2:30am    
i included the namespace but the same problem..is there any alternate to clear controls..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900