control name

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?Sm9obg==?=

    #1

    control name

    I want to dynamically get the control from the event being executed at a
    particular time. For example, lets say I have the following event.
    combobox1_Selec tedIndexChanged ((ByVal eventSender As System.Object, ByVal
    eventArgs As System.EventArg s) Handles combobox1.Selec tedIndexChanged

    I don't want to just specify combobox1. I need to dynamically get the
    control from the eventsender or some other method so I can write a generic
    function used for any control without having to specify the actual controls
    like comboBox1 or ComboBox2.

    I would really appreciate someone telling me how to do it.

    Thanks
  • =?Utf-8?B?Sm9obg==?=

    #2
    RE: control name


    Nevermind, I figured out I could just say the following:

    dim x as object
    x=eventsender

    I was trying to use the eventsender.get type.SOMETHING and didn't realize
    just setting x = to eventsender would give me everything I was after.

    Thanks
    "John" wrote:
    I want to dynamically get the control from the event being executed at a
    particular time. For example, lets say I have the following event.
    combobox1_Selec tedIndexChanged ((ByVal eventSender As System.Object, ByVal
    eventArgs As System.EventArg s) Handles combobox1.Selec tedIndexChanged
    >
    I don't want to just specify combobox1. I need to dynamically get the
    control from the eventsender or some other method so I can write a generic
    function used for any control without having to specify the actual controls
    like comboBox1 or ComboBox2.
    >
    I would really appreciate someone telling me how to do it.
    >
    Thanks

    Comment

    • rowe_newsgroups

      #3
      Re: control name

      On Mar 9, 10:21 am, John <J...@discussio ns.microsoft.co mwrote:
      Nevermind, I figured out I could just say the following:
      >
      dim x as object
      x=eventsender
      >
      I was trying to use the eventsender.get type.SOMETHING and didn't realize
      just setting x = to eventsender would give me everything I was after.
      >
      Thanks
      >
      "John" wrote:
      I want to dynamically get the control from the event being executed at a
      particular time. For example, lets say I have the following event.
      combobox1_Selec tedIndexChanged ((ByVal eventSender As System.Object, ByVal
      eventArgs As System.EventArg s) Handles combobox1.Selec tedIndexChanged
      >
      I don't want to just specify combobox1. I need to dynamically get the
      control from the eventsender or some other method so I can write a generic
      function used for any control without having to specify the actual controls
      like comboBox1 or ComboBox2.
      >
      I would really appreciate someone telling me how to do it.
      >
      Thanks
      Note that you can also cast the sender into a certain type instead of
      just leaving it as an object:

      i.e.

      private sub combobox_SomeEv ent(sender as object, e as eventargs)
      if (sender is Combobox)
      Dim cbo as ComboBox = DirectCast(send er, combobox)
      ' Do combobox specific stuff here
      else if (sender is TextBox)
      Dim tb as TextBox = DirectCast(send er, textbox)
      ' Do textbox specific stuff here
      end if
      end sub

      Thanks,

      Seth Rowe

      Comment

      • Herfried K. Wagner [MVP]

        #4
        Re: control name

        "rowe_newsgroup s" <rowe_email@yah oo.comschrieb:
        [...]
        if (sender is Combobox)
        ='If TypeOf sender Is ComboBox Then'.

        --
        M S Herfried K. Wagner
        M V P <URL:http://dotnet.mvps.org/>
        V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

        Comment

        • rowe_newsgroups

          #5
          Re: control name

          On Mar 9, 1:08 pm, "Herfried K. Wagner [MVP]" <hirf-spam-me-
          h...@gmx.atwrot e:
          "rowe_newsgroup s" <rowe_em...@yah oo.comschrieb:
          >
          [...]
          if (sender is Combobox)
          >
          ='If TypeOf sender Is ComboBox Then'.
          >
          --
          M S Herfried K. Wagner
          M V P <URL:http://dotnet.mvps.org/>
          V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
          To much C# lately :-)

          Thanks,

          Seth Rowe

          Comment

          Working...