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.CheckBoxToC hange' and 'System.Windows.Forms.Chec kBox'.
Here is my code:
Private Delegate Sub UpdateCheckBoxStateDelegat e(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 UpdateCheckBoxStateDelegat e(AddressO f UpdateCheckBoxState)
Me.BeginInvoke(ssd, New Object() {CheckBoxName, State})
Else
Select Case CheckBoxName
Case chkSystemActivation 'This is where the error occurs!!!!!!!!!!!!!!
chkSystemActivation.Checke d = State
End Select
End If
End Sub
Enum CheckBoxToChange
chkSystemActivation
End Enum
Any idea how to fix it?
Thanks in advance!
Regards,
Eric
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.CheckBoxToC
Here is my code:
Private Delegate Sub UpdateCheckBoxStateDelegat
Public Sub UpdateCheckBoxState(ByVal CheckBoxName As CheckBoxToChange, ByVal State As CheckState)
If Me.InvokeRequired Then
Dim ssd As New UpdateCheckBoxStateDelegat
Me.BeginInvoke(ssd, New Object() {CheckBoxName, State})
Else
Select Case CheckBoxName
Case chkSystemActivation 'This is where the error occurs!!!!!!!!!!!!!!
chkSystemActivation.Checke
End Select
End If
End Sub
Enum CheckBoxToChange
chkSystemActivation
End Enum
Any idea how to fix it?
Thanks in advance!
Regards,
Eric
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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.
ASKER
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.
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.
Private Delegate Sub UpdateCheckBoxStateDelegat
Public Sub UpdateCheckBoxState(ByVal CheckBoxName As CheckBoxToChange, ByVal State As CheckState)
If Me.InvokeRequired Then
Dim ssd As New UpdateCheckBoxStateDelegat
Me.BeginInvoke(ssd, New Object() {CheckBoxName, State})
Else
Select Case CheckBoxName
Case chkSystemActivation 'This is where the error occurs!!!!!!!!!!!!!!
CheckBoxToChange.chkSystem
End Select
End If
End Sub
Enum CheckBoxToChange
chkSystemActivation
End Enum