Link to home
Start Free TrialLog in
Avatar of indy500fan
indy500fan

asked on

Problem using a delegate to update a checkbox state

Friends,

I need to use a delegate to update a checkbox state, to keep from getting a cross-thread operation errors...

Anyway, I am getting an error:

Error      1      Operator '=' is not defined for types 'AYFS.AYFSMain.CheckBoxToChange' and 'System.Windows.Forms.CheckBox'.

Here is my code:

    Private Delegate Sub UpdateCheckBoxStateDelegate(ByVal CheckBoxName As CheckBoxToChange, ByVal State As CheckState)

    Public Sub UpdateCheckBoxState(ByVal CheckBoxName As CheckBoxToChange, ByVal State As CheckState)

        If Me.InvokeRequired Then

            Dim ssd As New UpdateCheckBoxStateDelegate(AddressOf UpdateCheckBoxState)

            Me.BeginInvoke(ssd, New Object() {CheckBoxName, State})
        Else
            Select Case CheckBoxName
                Case chkSystemActivation 'This is where the error occurs!!!!!!!!!!!!!!
                    chkSystemActivation.Checked = State
            End Select

        End If
    End Sub
    Enum CheckBoxToChange
        chkSystemActivation
    End Enum

Any idea how to fix it?

Thanks in advance!

Regards,
Eric
Avatar of PaulHews
PaulHews
Flag of Canada image

Change line with '<--- comment below...

Private Delegate Sub UpdateCheckBoxStateDelegate(ByVal CheckBoxName As CheckBoxToChange, ByVal State As CheckState)

    Public Sub UpdateCheckBoxState(ByVal CheckBoxName As CheckBoxToChange, ByVal State As CheckState)

        If Me.InvokeRequired Then

            Dim ssd As New UpdateCheckBoxStateDelegate(AddressOf UpdateCheckBoxState)

            Me.BeginInvoke(ssd, New Object() {CheckBoxName, State})
        Else
            Select Case CheckBoxName
                Case chkSystemActivation 'This is where the error occurs!!!!!!!!!!!!!!
                    CheckBoxToChange.chkSystemActivation.Checked = State   <---MAKE change here, so no conflict with actual checkbox!
            End Select

        End If
    End Sub
    Enum CheckBoxToChange
        chkSystemActivation
    End Enum
ASKER CERTIFIED SOLUTION
Avatar of PaulHews
PaulHews
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of indy500fan
indy500fan

ASKER

PaulHews,

Ah, the second solution works better.  That is interesting.  I've never had to do it that way, but I actually get it to compile now.

Thanks!

I'm getting ready to test in a couple of minutes.
Tested and it's perfect!  Thanks!
>Ah, the second solution works better.
The first one was a screw up on my part...

>I've never had to do it that way, but I actually get it to compile now.

Well, the actual name of the check box will refer to the checkbox object variable and not the enum type.  So you have to let the compiler know what you want.  

Normally in a Case statement, the intellisense will guide you, but the intellisense might have failed for some reason at the time.