Solved

Calling a button/menu click from another sub

Posted on 2004-09-20
4
690 Views
Last Modified: 2012-06-21
Hi,

In my code, I have a button (OK) that has code:

 Private Sub cmdOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOK.Click
         ...
 End Sub


In another spot, I have an icon shortcut as well as a keypress that should trigger this code - but unlike in VB6, I can't just say Call cmdOK_click

It seems to want arguments...  However, I don't know what sender or e really are.  I found that if I use

Call cmdOK_Click("", e)

it accepts "" for sender, but I can't find any null-type expression to replace e with, (0, "", '', null, etc)

What do I need to do to trigger a _click event from another sub?

JP
0
Comment
Question by:gleznov
4 Comments
 

Author Comment

by:gleznov
ID: 12104791
OK I cheated - I put the code from the _click into it's own private sub, then just called it without the call command in both _click and the other routines.  However, I'd still like to know if there was an answer to my original question?

JP
0
 
LVL 2

Expert Comment

by:Mehrdad_Y
ID: 12104944
Hello, you have two ways:
1- cmdOk_Click(nothing, new System.EventArgs())
2- Me.cmdOK.PerformClick()
0
 
LVL 5

Assisted Solution

by:tzxie2000
tzxie2000 earned 125 total points
ID: 12104951
you can just call cmdOK_Click(Nothing, Nothing)
but you should not use object and e in cmdOK_Click
0
 
LVL 3

Accepted Solution

by:
imu79 earned 125 total points
ID: 12105290
It depends on what exactly you're trying to do. If you actually want to 'fire' the event, then you can call the PerformClick method of the button to raise the click event for the button. If you simply want to execute the code in the click event handler, you can directly call the procedure as mentioned in the previous to comments. A more cleaner solution would be to have your event handling procedure call another private procedure and whenever you want to execute the event handling code, you can directly call the private procedure and not worry about passing parameters into the event handing procedure.

Something like this:

Private Sub cmdOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOK.Click
        ClickEventProcedure( )
End Sub

Private Sub ClickEventProcedure( )
    ' click event handing code...
End Sub

Private Sub AnotherSub( )
    ClickEventProcedure( )
End Sub

Ofcourse, your click event handler is using the sender and the event arguments for whatever processing you're doing, you would need to pass them in to this private event procedure. But that would defeat the whole purpose of not having to pass the event arguments. I guess in the end it all boils down what exactly is the purpose of executing the  event handling code - based on that you can decide which method best suites your requirements.

hope that helps..
Imran.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now