Addressing specific type of control on a form

  • Thread starter Thread starter John Suru
  • Start date Start date
J

John Suru

How do I cycle through all controls on a form singling
out just textboxes and comboboxes and clearing their text
property? I think I need to address the controls
collection and only clear the text property if the
control is a textbox or a combobox. How do I do this?

Thanks,
John Suru
 
Hi John, try using 'typeof':

ex
\\
dim myControl as System.Windows.Forms.Control

For Each myControl in myForm.Controls

if ((typeof myControl is System.Windows.Forms.TextBox) orelse _
(typeof myControl is System.Windows.Forms.Label)) Then

myControl.Text = String.Empty

end if

next
//

code written off the top of my head so watch out for syntax...

hope this helps,

jim
 
Back
Top