Link to home
Start Free TrialLog in
Avatar of Ameerh24
Ameerh24

asked on

get the type of control

how can I get the type of control ?
what I was trying to find so function that return the type of control so I can get all textbox controls in a form
note that I am using vs.net 2008
SOLUTION
Avatar of p_davis
p_davis

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of p_davis
p_davis

for processing

if(ctrl.GetType() == typeof(TextBox))
{}
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
you can also use this

        Dim ctl As Control
        For Each ctl In Me.Controls
            If TypeOf ctl Is TextBox Then
            End If
        Next
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Ameerh24

ASKER

Idle_Mind, why are u making recursion ?
As I said before:

    "The solutions above will only find TextBoxes at the "first" level...those that are contained directly by the Form.  It would not find those contained by a Panel for instance."

Specificly, the previous solutions are using:

    For Each ctl As Control In Me.Controls

Assuming the "Me" (or "this" for C#) refers to a Form, this would only iterate over the controls that are DIRECTLY contained by the Form.  If you placed a GroupBox, Panel, or some other container on the form, and then placed TextBoxes INSIDE that container, those TextBoxes would not be found by the For...Next looping structure.

Thus the need for recursion.  For each container control it encounters, the FindAllTextBoxes() method is called again so that the child controls for that container can also be inspected.  The recursion will "drill down" thru the control hierarchy...
thanks Idle_Mind, that's really easy, clear and accurate