[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 200
  • Last Modified:

system.EventHandler with variable

Is there any what to attach a variable to an event handler?

IE:
oEventHandler = New System.EventHandler(AddressOf ChangeInstance(i))

Thanks!
   - Marc
0
MarcGraff
Asked:
MarcGraff
  • 3
  • 2
3 Solutions
 
gregoryyoungCommented:
not sure which side you are asking for here ...

dim foo as new EventHandler(AddressOf MyRoutine)

is fine ...

New System.EventHandler(AddressOf ChangeInstance(i)) this is not ... what exactly are you trying to do here? is ChangeInstance(i) accessing an array of event handlers or are you trying to tell it to pass some arbitrary value i to the event when it run?


0
 
b1xml2Commented:
Public Class MyCustomClass
   
    Public Event ClickIt As ClickItEventHandler

    Private Sub OnClickIt(ByVal args As ClickItEventArgs)
        RaiseEvent ClickIt(Me, args)
    End Sub
   
    Public Sub UseIt(ByVal user As String)
      OnClickIt(New ClickItEventArgs(user))
    End Sub

End Class

Public Delegate Sub ClickItEventHandler(ByVal sender As Object, ByVal args As ClickItEventArgs)

Public Class ClickItEventArgs
    Inherits EventArgs

    Public ReadOnly User As String
    Public Sub New(ByVal user As String)
        Me.User = user
    End Sub
End Class


0
 
b1xml2Commented:
you can pass in values/objects to your events by
1. creating your class that inherits from the EventArgs class
2. creating the matching delegate signature
3. implement the custom event
4. create the entry point in which one can invoke/raise the event
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
MarcGraffAuthor Commented:
gregoryyoung:

What I am attempting to accomplish is to have a form that is a single record in a table. I want a menu that has an entry (menu item) for each record in the table. There for I want to send the index of the record in the table along with the on click event of the menu.

b1xml2:
Hmm ok, that is a bit advanced for me but I will give it a shot.

Thanks!
0
 
b1xml2Commented:
Marc,

use Custom Events then:

and have the appropriate objects subscribe to this event:

Public Class MyCustomClass

      Public Event RowIndexSelected As RowIndexSelectedEventHandler
      
      Private Sub MenuItem_Clicked(ByVal sender As Object,ByVal e As EventArgs) Handles MenuItem1.Clicked
            Dim index As Integer = 10
            RaiseEvent RowIndexSelected(Me,New RowIndexSelectedEventArgs(index))
      End Sub

End Class

Public Delegate Sub RowIndexSelectedEventHandler(ByVal sender As Object, ByVal args As RowIndexSelectedEventArgs)

Public Class RowIndexSelectedEventArgs
    Inherits EventArgs

    Public ReadOnly ItemIndex As Integer
    Public Sub New(ByVal index As Integer)
        Me.ItemIndex = index
    End Sub
End Class
 

0
 
MarcGraffAuthor Commented:
Thanks! With some effort I've got it! Thanks so much!

   - Marc
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now