B
Brian P. Hammer
I have an app that allows users to supply custom values for various
calculations; about 43 of them. I use checkboxes to identify the use or
lack there of, of a custom value. I need to be able to tell when the check
state changes. Instead of coding for each one of the 43 check boxes and text
boxes, I'd like to have one sub that checks. I thought I would just add the
name of the textbox to the checkbox tag and ctype it but I get an invalid
cast exception. Here's what I am trying to accomplish:
Private Sub chkFlightBlock_CheckedChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles chkFlightBlock.CheckedChanged, ....,
....., chkAnotherCustom
Dim ctl As TextBox
ctl = CType(sender, CheckBox).Tag
ctl.Enabled = CType(sender, CheckBox).Checked
If CType(sender, CheckBox).Checked Then
ctl.BackColor = System.Drawing.SystemColors.Window
Else
ctl.BackColor = System.Drawing.SystemColors.Control
End If
End Sub
In essence, I'd like to store the name of the textbox in the checkbox and
handle my code in one area instead of many different subs. Any help would be
great.
Thanks,
Brian
calculations; about 43 of them. I use checkboxes to identify the use or
lack there of, of a custom value. I need to be able to tell when the check
state changes. Instead of coding for each one of the 43 check boxes and text
boxes, I'd like to have one sub that checks. I thought I would just add the
name of the textbox to the checkbox tag and ctype it but I get an invalid
cast exception. Here's what I am trying to accomplish:
Private Sub chkFlightBlock_CheckedChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles chkFlightBlock.CheckedChanged, ....,
....., chkAnotherCustom
Dim ctl As TextBox
ctl = CType(sender, CheckBox).Tag
ctl.Enabled = CType(sender, CheckBox).Checked
If CType(sender, CheckBox).Checked Then
ctl.BackColor = System.Drawing.SystemColors.Window
Else
ctl.BackColor = System.Drawing.SystemColors.Control
End If
End Sub
In essence, I'd like to store the name of the textbox in the checkbox and
handle my code in one area instead of many different subs. Any help would be
great.
Thanks,
Brian