problem with checkbox

L

luca.gere

I have a problem.
I'd like, when i click on a button , to check all the checkbox that i
have in the form.

I have tried with :

For Each Myobj As Control In Me.Controls
If TypeOf Myobj Is CheckBox Then
If Myobj.checked Then
...
...
...
End If
End If
Next

but i have an error on myobj.checked :
'checked' in not a member of 'system.windows.forms.controls'

Thank you
Luca
 
A

Al Reid

luca.gere said:
I have a problem.
I'd like, when i click on a button , to check all the checkbox that i
have in the form.

I have tried with :

For Each Myobj As Control In Me.Controls
If TypeOf Myobj Is CheckBox Then

Change the following line:
If Myobj.checked Then

to:

If CType(Myobj, CheckBox).checked Then
...
...
...
End If
End If
Next

but i have an error on myobj.checked :
'checked' in not a member of 'system.windows.forms.controls'

Thank you
Luca

I hope that helps.
 
L

luca.gere

the line i use it to control re state of the check box and i'd like to
chenge it.
for example

If Myobj.checked Then
Myobj.checked=false
else
Myobj.checked=true
endif
 
A

Al Reid

--
Al Reid

"It ain't what you don't know that gets you into trouble. It's what you know
for sure that just ain't so." --- Mark Twain

luca.gere said:
the line i use it to control re state of the check box and i'd like to
chenge it.
for example

If Myobj.checked Then
Myobj.checked=false
else
Myobj.checked=true
endif

Perhaps the following instead:

If TypeOf Myobj Is CheckBox Then
Dim MyCheck As Checkbox = CType(Myobj, CheckBox)
If MyCheck.checked Then
MyCheck.checked=false
Else
MyCheck.checked=true
End If
End If

Or maybe:

If TypeOf Myobj Is CheckBox Then
CType(Myobj, CheckBox).Checked = Not CType(Myobj, CheckBox).Checked
End If

I hope that helps.
 

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