By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,815 Members | 1,066 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,815 IT Pros & Developers. It's quick & easy.

Just trying to iterate over controls...

P: n/a
A
HI all,

I am trying to iterate over all the controls on my form and if a control IS
A textbox then I want to enter the If statement. So far I can't get it to
work...here is the code...any help?

For Each c As Control In Me.Controls

If c.GetType() Is System.Type.GetType("TextBox") Then

Do something useful....

End If

Next
Nov 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

"A" <no****@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
HI all,

I am trying to iterate over all the controls on my form and if a control IS A textbox then I want to enter the If statement. So far I can't get it to
work...here is the code...any help?

For Each c As Control In Me.Controls

If c.GetType() Is System.Type.GetType("TextBox") Then

Do something useful....

End If

Next

Try this instead.

For Each objControl In Controls

If TypeOf (objControl) Is TextBox Then

objControl.Text = "Yippee!"

' or, something useful

End If

Hope this helps.
--
Peter [MVP Visual Developer]
Jack of all trades, master of none.

Next
Nov 20 '05 #2

P: n/a
Hi A,

It looks the same as from Peter, however this does as well the controls in
by intance a panel. When you do not have those take the one from Peter.

\\\\
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
doYippy(Me)
End Sub
Private Sub doYippy(ByVal parentCtr As Control)
Dim ctr As Control
For Each ctr In parentCtr.Controls
If TypeOf ctr Is TextBox Then
ctr.Text = "Yippy"
End If
doYippy(ctr)
Next
End Sub
///
I hope this helps?

Cor
Nov 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.