Getting Comboboxes and Textboxes from Form

  • Thread starter Thread starter Werner Wopienka
  • Start date Start date
W

Werner Wopienka

HI NG!

Is there a better way then this code below, to get all Textboxes and
Comboboxes from a form:

Private i as Integer
Private ctrcoll As ControlCollection

ctrcoll = Me.Controls

Try
If (ctrcoll(i) Is CType(ctrcoll(i), TextBox)) Then
ctrcoll(i).Focus()
Else
If (ctrcoll(i) Is CType(ctrcoll(i), ComboBox)) Then
MsgBox("combo")
End If
End If
Catch ex As Exception
End Try

Thx 4 any advice

Werner
 
In VB you can use the TypeOf keyword e.g.

For Each ctl As Control In Me.Controls

If TypeOf (ctl) Is Label Then

MessageBox.Show(CType(ctl, Label).Text.ToString())

End If

Next



Peter
 

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