Click here to Skip to main content
15,903,201 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
VB
For Each cControl In Me.Controls
  If (TypeOf cControl Is TextBox) Then
          End If
          If (TypeOf cControl Is CheckBox) Then
          End If
          If (TypeOf cControl Is ComboBox) Then
          End If
          If (TypeOf cControl Is RadioButton) Then
          End If
        next cControl


What I have tried:

tryed me best effort to make a quality but ?
Posted
Updated 21-Jan-17 21:59pm
Comments
Richard MacCutchan 22-Jan-17 3:46am    
So what is the problem?
Afzaal Ahmad Zeeshan 22-Jan-17 3:52am    
This is fine. You cannot make VB.NET check the types itself also. You have to write this code.

1 solution

Not quite sure of your question as the code you show will work, however if you have controls inside a container like a tabcontrol you need to iterate those controls separately as they are not members of the container you are iterating.

Easiest way is to use a recursive function passing the container control as argument and calling itself when it find a control has children passing that control as argument.

Quick example (not tested written of the top of my head).

VB
public sub WalkControls(TopControl as Control)
   For Each x As Control In TopControl.Controls
       If x.HasChildren Then
          WalkControls(x)
       Else
'
' Do what you want to do with the control
'
       End If
   Next
End sub
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900