Controls function

J

James

I have three checkbox that I want to check the state (checkbox1
checkbox2 checkbox3

I do the following

Dim i As Integer
Dim chk As New CheckBox
For i = 1 To 3
chk = (Controls("CheckBox" & CStr(i)))
If chk.CheckState = CheckState.Unchecked Then
.....Code
End If
Next

This works if the checkbox are NOT in a Panel only. Why??
 
A

Armin Zingler

I have three checkbox that I want to check the state (checkbox1
checkbox2 checkbox3

I do the following

Dim i As Integer
Dim chk As New CheckBox
For i = 1 To 3
chk = (Controls("CheckBox" & CStr(i)))
If chk.CheckState = CheckState.Unchecked Then .....Code
End If
Next

This works if the checkbox are NOT in a Panel only. Why??

Because they are not controls in the Form but controls in the Panel. Use
this instead:

chk = YourPanel.Controls("CheckBox" & CStr(i))

Armin
 
R

rowe_newsgroups

Because they are not controls in the Form but controls in the Panel. Use
this instead:

chk = YourPanel.Controls("CheckBox" & CStr(i))

Armin

Just adding to Armin. If the only checkboxes your panel contains are
the checkboxes you want to investigate you could do this (as I hate
getting controls by name):

<pseudocode>

For each ctl as Control in YourPanel.Controls
If typeof(ctl) is Checkbox andalso directcast(ctl,
Checkbox).CheckState = CheckState.Unchecked then
' Do Stuff
End If
Next

</pseudocode>

Thanks,

Seth Rowe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top