• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 204
  • Last Modified:

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
0
indy500fan
Asked:
indy500fan
  • 3
  • 2
1 Solution
 
PaulHewsCommented:
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
0
 
PaulHewsCommented:
Oops... Mistake.  Try again...
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 CheckBoxToChange.chkSystemActivation '<---MAKE change here, so no conflict with actual checkbox!
                    chkSystemActivation.Checked = State   actual checkbox!
            End Select

        End If
    End Sub
    Enum CheckBoxToChange
        chkSystemActivation
    End Enum
0
 
indy500fanAuthor Commented:
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.
0
 
indy500fanAuthor Commented:
Tested and it's perfect!  Thanks!
0
 
PaulHewsCommented:
>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.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now