not a member of Control?

t_jcruise

Member
Joined
Jul 16, 2010
Messages
10
Programming Experience
Beginner
I'm having a problem at my code. The for each command...

Private Sub cmdVoidOrder_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdVoidOrder.Click
Dim ctrl As Control

For Each ctrl In grpOderDetails.Controls
If TypeOf ctrl Is CheckBox Then
If ctrl.checked = True Then
'Syntax to void order
End If
End If
Next
End Sub


In VB 6.0 it does not have any error but when i Used it in .Net it has an error:


Error 1 'checked' is not a member of 'System.Windows.Forms.Control'.

any suggestions?

Because there's no control array in .Net I would like to validate the checkboxes using For Each command.

If a checkbox is checked then I would Void the order... its just a basic Sales Order system...

heres the sample image...
35141_1420381202983_1636276034_971527_1033249_n.jpg
 
Welcome to the forum :)

When posting code please use the code tags as it makes it much easier to read :)

The problem is that you're not converting the control into its correct type (in this case a CheckBox), you would probably want to do something like this;
VB.NET:
    Private Sub cmdVoidOrder_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdVoidOrder.Click
        Dim ctrl As Control
        Dim chk As CheckBox

        For Each ctrl In grpOderDetails.Controls
            If TypeOf ctrl Is CheckBox Then
                chk = CType(ctrl, CheckBox)
                If chk.Checked = True Then
                    'Syntax to void order
                End If
            End If
        Next
    End Sub

I hope that this helps

Satal :D
 
Back
Top