Just trying to iterate over controls...

  • Thread starter Thread starter A
  • Start date Start date
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
 
A said:
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.
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top