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
 
Back
Top