Find values of properties of checkbox

  • Thread starter Thread starter Mike P
  • Start date Start date
M

Mike P

How do you find the values of a property (such as whether or not they
are checked) when the check boxes have been created on the fly?

Any help would be much appreciated!
 
Mike P said:
How do you find the values of a property (such as whether or not they
are checked) when the check boxes have been created on the fly?

Is it a Web or WinForms application?

If you did not keep a Reference to the checkboxes when you created them,
you can always iterate over the Controls collection to recover the
checkboxes. This should work both in WinForms and WebForms (on the condition
that the checkboxes are created on every postback if it is a WebForm). On
WebForms, you can also use the Form[] collection to recover the posted
values by their name.
 
Mike said:
How do you find the values of a property (such as whether or not they
are checked) when the check boxes have been created on the fly?

Any help would be much appreciated!

You would have a routine that iterates through the Controls Collection
on the form and check for control type.

This is a vb.net example and it's for a Web form, but it's the same
thing on a Web or Windows form.

You would iterate thought the Controls Collection looking for the type
of control and work with it. You can find some code in C#.Net that does
the same -- use google.

<http://articles.techrepublic.com.com/5100-10878_11-6157618.html>


Controls collection

The form maintains a collection of controls that you can utilize to loop
through in order to change a certain property that you want to update in
runtime.

For example, add two textboxes to a form and add the following code:

Private Sub SetControls()
Dim cControl As Control

For Each cControl In Me.Controls
If (TypeOf cControl Is TextBox) Then
cControl.Text = "abc"
End If
Next cControl
End Sub
 
Back
Top