Johnny Prescott
Johnny Prescott

Reputation: 271

Calling Public Sub with Handles

Trying to do something that is probably simple. I have an event firing when you active an Item in a listview.

I want to call this event from another place (a timer in this case but this shouldn't change much).

My Sub:

Public Sub AccountChecker_AccountList_ItemActivate(sender As Object, e As EventArgs) Handles AccountChecker_AccountList.ItemActivate
    [...My Code]
End Sub

I want to have this execute even if I did not activated the item. However, I can find anything to "click" the listview item.

I tried with something like this:

AccountChecker_AccountList_ItemActivate(x,y)

I probably need x and y to do this. What are the object and EventArgs in this function so i can call it?

regards,

Upvotes: 0

Views: 177

Answers (2)

mr_w_snipes
mr_w_snipes

Reputation: 171

If i understand you correctly you cannot trigger the sub that is called by the eventhandler for the itemactivate-event. You could just write a function or a sub that does what you need. If you need the name of the item that is activated, you can just pass it as an argument into your sub / function. You can call it when the event is fired or when the timer is where you want it to be. You can add parameters to your function to extend it. That also makes it much easier to reuse your code :)

 Private Sub BTN_Run_Click(sender As Object, e As EventArgs) Handles BTN_Run.Click

    ListViewAction(ListViewItem)

End Sub

public sub ListViewAction(byval ListviewItem as string)
' do your stuff here 
end sub 

Upvotes: 3

Mark
Mark

Reputation: 8160

The sender is usually the object calling the method, so you can use Me. You can use EventArgs.Empty for e, i.e.

AccountChecker_AccountList_ItemActivate(Me, EventArgs.Empty)

However, it may depend on what you actually do with sender in [...My Code] - some handlers may expect it to be a specific type and may not like being passed a random object!

Upvotes: 1

Related Questions