Results 1 to 3 of 3

Thread: [2005] Passing Extra Parameters to Event Handlers

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    5

    [2005] Passing Extra Parameters to Event Handlers

    I was wondering if there was a way to add an EventHandler in response to a Click that takes more parameters then
    VB Code:
    1. (ByVal sender As System.Object, ByVal e As System.EventArgs)
    when adding these to dynamic buttons. Right now I am creating seperate handlers for each new button, which does not solve my problem very well. Any help is appreciated.

    Here is my switch statement if you don't understand exactly what I am trying to say...

    VB Code:
    1. Select Case (numberButtons)
    2.             Case 0 : AddHandler buttonArray(numberButtons).Click, AddressOf dynamicButton1_Click
    3.             Case 1 : AddHandler buttonArray(numberButtons).Click, AddressOf dynamicButton2_Click
    4.             Case 2 : AddHandler buttonArray(numberButtons).Click, AddressOf dynamicButton3_Click

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,383

    Re: [2005] Passing Extra Parameters to Event Handlers

    you can use a single event to handle each button click... the sender object that is passed in will be equal to the button that was pressed...

    for example, after you link your buttons to the single DoSomething handler using AddHandler, you can tell which button actually fired the event like this:
    VB Code:
    1. Private Sub DoSomething(sender as object, e as eventargs)
    2.     Select Case Sender
    3.         Case Is buttonArray(0)
    4.              'do something
    5.         Case Is buttonArray(1)
    6.              'do something
    7.     End Select
    8. End Sub

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    5

    Re: [2005] Passing Extra Parameters to Event Handlers

    Thanks Kleinma. I guess I was just ignoring those variables, since I didn't know what they represented. That will do much better than what I was doing before. Thanks again

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