Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi For All
I Want Disable All TextBox in my form using for each command such as
VB
for each control ontrol in me.controls
    if control.gettype is gettype textbox then
         control.enable=false
    end if
next

But I have written mistake code please help me
thanks
Posted
Updated 11-Aug-20 14:24pm
v2

Try:
VB
For Each c As Control In Controls
    Dim t As TextBox = TryCast(c, TextBox)
    If t IsNot Nothing Then
        t.Enabled = False
    End If
Next
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 1-Jan-12 9:53am    
Sure, a 5.
--SA
Try
VB
for each control ontrol in me.controls
    if ontrol.gettype is gettype textbox then
         ontrol.enable=false
    end if
next
 
Share this answer
 
There you go
VB
For Each ctl As Control in Me.Controls 
 If TypeOf(ctl) Is TextBox Then 
    ctl.Enabled = False
 End If 
Next 
 
Share this answer
 
Comments
Richard MacCutchan 18-May-20 6:59am    
Copying other people's code from eight years ago is not really a valid solution.
codejet 19-May-20 10:43am    
I came across that code in a training kit for MCSD (VB 6.0 ) when I was still a student in 2006. I am not claiming to be the originator of the code. So because I am not the originator of the code that disqualifies it as a valid solution?
Richard MacCutchan 19-May-20 10:59am    
The question was solved eight years ago. And it looks like you just copied an existing solution and posted it as your own. But either way, please stick to current open questions, do not resurrect ones that are long inactive.

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