PDA

Click to See Complete Forum and Search --> : getting an object's label by using sender.text


Psychotron
Jul 29th, 2002, 06:39 PM
This is the code i have, but it's not working. what i want is for the label of the object i'm clicking on to appear in the textbox:


Sub Generic()
Dim Ctl As Control
For Each Ctl In Controls
AddHandler Ctl.Click, AddressOf GenericClick
Next
End Sub

Sub GenericClick(ByVal sender As Object, ByVal e As System.EventArgs)
CustSummaryTxt.Text = sender.text

End Sub

on Form_Load i'm calling Generic(), but the code doesn't work. nothing is displayed in my textbox when i click on a control.

Dr_Evil
Jul 29th, 2002, 10:06 PM
hmm... I just tried your code and it worked fine for some controls but not all of them. Here's a small rundown.

LinkLabel - OK
Button - OK
CheckBox - OK
Label - OK
RadioButton - OK
TreeView - NO
DataGrid - NO
GroupByBox - NO
DateTimePicker - NO

I'm not sure why this is, and I'd imagine there's a work around. Let me play around with this for awhile. I'll let you know if I find anything.

Psychotron
Jul 30th, 2002, 01:00 AM
thanks for the help. i determined what my problem is. the text of the control will only appear in the textbox as long as the control isn't in a container. so i'm trying to figure out how to get it to appear for my controls in my groupboxes.

I tryed changing Dim Ctl as Control to Dim Ctl as ControlContainer, but i get an exception when i run the program.

Thanks, Brad.

Dr_Evil
Jul 30th, 2002, 08:30 AM
Try this.


Dim objControl As Control

For Each objControl In Me.GroupBox1.Controls
AddHandler objControl.Click, AddressOf GenericClick
Next