Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple events :Casting from Button to CheckBox

Status
Not open for further replies.

Gigaz

Technical User
Dec 5, 2007
11
AU
Hi,
Can anybody help me with following problem. I'm trying to use multievent. I created chkMultiUse and I'm trying to use it in sub myClickHandler, nut I'm getting error: Unable to cast object type Buttons to type CheckBox. I know should change in some way chkMultiUse. Please any help will be appreciated.
Code:
    Private Sub chkMultiUse_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _
         Handles chk1.CheckedChanged, chk2.CheckedChanged, chk3.CheckedChanged
        Dim chkMultiUse As CheckBox
        chkMultiUse = CType(sender, CheckBox)
        If chkMultiUse.Checked Then
            AddHandler btnDelete.Click, AddressOf myClickHandler
        Else
            RemoveHandler btnDelete.Click, AddressOf myClickHandler
        End If
    End Sub
    Private Sub myClickHandler(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim iResponce As Integer
        Dim chkMultiUse As CheckBox
        chkMultiUse = CType(sender, CheckBox)
        iResponce = MsgBox("Are You Sure You want to delete check box", vbYesNo, "DELETE CHECKBOX")
        If iResponce = vbYes And chkMultiUse.Checked Then ' They Clicked YES!
            chkMultiUse.Visible = False
        Else
            chkMultiUse.Visible = True
            chkMultiUse.Checked = False
        End If
End Sub
Thanks, Gigaz
 
Please where is forum796,
Thanks
 
There you go, you've successfully created the correct link yourself :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top