Hello to all,
I want to display value of "text" property of checkbox when it is clicked.
So with checkedChanged event 2 arguments of type sender & eventArgs are passed.
So can anybody get me know how to do the same using these arguments.
Hello to all,
I want to display value of "text" property of checkbox when it is clicked.
So with checkedChanged event 2 arguments of type sender & eventArgs are passed.
So can anybody get me know how to do the same using these arguments.
You have tagged with both C# and VB.net, which are you using? Depending on this you can use one of the following to get the CheckBox which fired the argument:
C#:
(CheckBox)sender
VB:
CType(sender, CheckBox)
You can then check the Text property of the object
Yes, but do you possibly also want to unset it if it's unchecked?
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
If CType(sender, CheckBox).Checked Then
Label1.Text = CType(sender, CheckBox).Text
Else
Label1.Text = ""
End If
End Sub
Seems to me that the answers suggested thus far are overkill in that the sub has the "Handles" qualifier... this means the ONLY time this will get called is when the Checkbox1 is modified. So you could use: Checkbox1.text directly.
The answers above are better suited for a more generic case where you want the SAME routine to HANDLE many checkboxes and so need to down_select to the appropriate ("calling") checkbox.
The subtlety here, Mr. Tejas, is that the NAME of the SUB (i.e. Checkbox1_CheckChanged) may or may not have anything to do with Checkbox1 depending upon the HANDLES phrase at the end.