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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
you can also use this
Dim ctl As Control
For Each ctl In Me.Controls
If TypeOf ctl Is TextBox Then
End If
Next
Dim ctl As Control
For Each ctl In Me.Controls
If TypeOf ctl Is TextBox Then
End If
Next
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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...
"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...
ASKER
thanks Idle_Mind, that's really easy, clear and accurate
if(ctrl.GetType() == typeof(TextBox))
{}