Results 1 to 4 of 4

Thread: getting an object's label by using sender.text

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2002
    Posts
    121

    getting an object's label by using sender.text

    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:


    Code:
    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.

  2. #2
    Lively Member Dr_Evil's Avatar
    Join Date
    Mar 2000
    Location
    Columbus, OH
    Posts
    105

    Question

    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.
    Dr_Evil
    Senior Programmer
    VS6 EE
    VS.NET EA

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Apr 2002
    Posts
    121
    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.

  4. #4
    Lively Member Dr_Evil's Avatar
    Join Date
    Mar 2000
    Location
    Columbus, OH
    Posts
    105
    Try this.

    Code:
            Dim objControl As Control
    
            For Each objControl In Me.GroupBox1.Controls
                AddHandler objControl.Click, AddressOf GenericClick 
            Next
    Dr_Evil
    Senior Programmer
    VS6 EE
    VS.NET EA

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width