Board index » Visual Studio » Disable all text boxes on form at once

Disable all text boxes on form at once

Visual Studio129
how would you disable all text boxes on a form at once/



I thought



dim tx as textbox

for each tx in me.controls

tx.enabled = false

next



but that crashes, what do you guys suggest? thanks


-
 

Re:Disable all text boxes on form at once

* "Brian Henry" <brianiupmsdn@newsgroups.nospam>scripsit:

Quote
how would you disable all text boxes on a form at once/



I thought



dim tx as textbox

for each tx in me.controls

tx.enabled = false

next



but that crashes, what do you guys suggest?



<URL:dotnet.mvps.org/dotnet/samples/controls/downloads/EnumerateControls.zip>">dotnet.mvps.org/dotnet/samples/controls/downloads/EnumerateControls.zip>



--

Herfried K. Wagner [MVP]

<URL:dotnet.mvps.org/>">dotnet.mvps.org/>

-

Re:Disable all text boxes on form at once

"Brian Henry" <brianiupmsdn@newsgroups.nospam>wrote in message

Quote
how would you disable all text boxes on a form at once/



I thought



dim tx as textbox

for each tx in me.controls

tx.enabled = false

next



but that crashes, what do you guys suggest? thanks



Dim c As Control

For Each c In Me.Controls

If TypeOf c Is TextBox Then

c.Enabled = False

End If

Next



--

Sven Groot



-

Re:Disable all text boxes on form at once

"Brian Henry" <brianiupmsdn@newsgroups.nospam>wrote in message

Quote
how would you disable all text boxes on a form at once/



dim tx as textbox

for each tx in me.controls



This will /only/ work if /every/ control on the form is a TextBox.

Otherwise, it will get upset trying to cast, say, a Label into your

TextBox variable.



Try this (I'm using VB'2003 here)



For Each ctl as Control in Me.Controls

If ctl Is TextBox Then

ctl.Enabled = False

End If

Next



HTH,

Phill W.





-

Re:Disable all text boxes on form at once

Hi Brian,



The one I like, I typed it in here so watch typos



I hope this helps



Cor



\\\\

Private sub Set

doset(Me)

end sub

Private Sub doSet(ByVal parentCtr As Control)

Dim ctr As Control

For Each ctr In parentCtr.Controls

if typeof ctr is textbox then

ctr.enabled = false

end if

doSet(ctr)

Next

End Sub

////





-

Re:Disable all text boxes on form at once

"Brian Henry" <brianiupmsdn@newsgroups.nospam>schrieb

Quote
how would you disable all text boxes on a form at once/



I thought



dim tx as textbox

for each tx in me.controls

tx.enabled = false

next



but that crashes, what do you guys suggest? thanks



Not all controls on the Form are textboxes, so whenever, within the loop, a

control is assigned to 'tx' that is not a textbox, an InvalidCastException

occurs. Instead:



dim o as object

for each o in me.controls

if typeof o is textbox then

directcast(o, textbox).enabled = false

end if

next



Note that this only processes the Textboxes directly placed on the Form, not

those eg placed on a groupbox on the Form.





--

Armin



How to quote and why:

www.plig.net/nnq/nquote.html">www.plig.net/nnq/nquote.html

www.netmeister.org/news/learn2quote.html">www.netmeister.org/news/learn2quote.html



-

Re:Disable all text boxes on form at once

Hi Armin,



Quote
Note that this only processes the Textboxes directly placed on the Form,

not

those eg placed on a groupbox on the Form.



Have a look at that nice routine I made for it.

(It is one of them of course, however this one I like specially in this

situation, it is very good when you have to set one handler for all

controls)



Cor





-

Re:Disable all text boxes on form at once

oh yes, the is.. dumb me forgetting about types





"Sven Groot" <sveng3000@gmx.net>wrote in message

Quote
"Brian Henry" <brianiupmsdn@newsgroups.nospam>wrote in message

news:edLUZXsLEHA.3216@tk2msftngp13.phx.gbl...

>how would you disable all text boxes on a form at once/

>

>I thought

>

>dim tx as textbox

>for each tx in me.controls

>tx.enabled = false

>next

>

>but that crashes, what do you guys suggest? thanks



Dim c As Control

For Each c In Me.Controls

If TypeOf c Is TextBox Then

c.Enabled = False

End If

Next



--

Sven Groot







-

Re:Disable all text boxes on form at once

"Armin Zingler" <az.nospam@freenet.de>schrieb

[bla]



sorry for sounding like an echo... ;)





--

Armin





-