how to invoke a button Click Event programmatically?

G

Guest

My from contains a "Move Next" button. When the user clicks on the "Move
Next" button - several procedures get invoked and eventually, the dataset
underlying the form will display main data from the next record and will
display detail data in a datagridview also on the form which is related to
the current main record in view.

Another button ("Transfer Account") on the form can modify what detail data
is related to the current main record. When this button gets clicked I have
to update the view the form is currently displaying. This means I have to
reload the main data and detail data and increment the dataset to display the
main record that was currently in view and display the modified detail data.

If the main dataset contains 10 records, and the user is on record 7, the
form needs to display record 7 after the "Transfer Account" button has been
clicked and also display the updated Detail records in the datagrid view.
Say there were 5 detail records in the datagridview for main record 7. Then
2 detail records get transferred out. I need to reload the whole dataset so
that main and detail data remain synchronized.

Reloading the dataset is easy - except that I end up on the first record. I
need to move next till I am back on the 7th record. Rather than rewriting
the Move Next code in the "Transfer Account" button, is there a way I can
programmatically invoke the MoveNext Click event? How to do this?

Thanks,
Rich
 
G

Guest

Private Sub btnMoveNext_Click(...) Handles btnMoveNext.Click

If I call btnMoveNext_Click -- that won't interfere with the Handles part?
I guess I am going to find out.
 
G

Guest

Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)

This is the part I am having the problem with - the event args
 
G

Guest

If I call btnMoveNext_Click -- that won't interfere with the Handles
part? I guess I am going to find out.

Nope :)

For the paramters, just pass in dummy values (null or new eventargs, etc)
 
R

RickH

My from contains a "Move Next" button. When the user clicks on the "Move
Next" button - several procedures get invoked and eventually, the dataset
underlying the form will display main data from the next record and will
display detail data in a datagridview also on the form which is related to
the current main record in view.

Another button ("Transfer Account") on the form can modify what detail data
is related to the current main record. When this button gets clicked I have
to update the view the form is currently displaying. This means I have to
reload the main data and detail data and increment the dataset to display the
main record that was currently in view and display the modified detail data.

If the main dataset contains 10 records, and the user is on record 7, the
form needs to display record 7 after the "Transfer Account" button has been
clicked and also display the updated Detail records in the datagrid view.
Say there were 5 detail records in the datagridview for main record 7. Then
2 detail records get transferred out. I need to reload the whole dataset so
that main and detail data remain synchronized.

Reloading the dataset is easy - except that I end up on the first record. I
need to move next till I am back on the 7th record. Rather than rewriting
the Move Next code in the "Transfer Account" button, is there a way I can
programmatically invoke the MoveNext Click event? How to do this?

Thanks,
Rich

Like other said calling the click event function directly is least
clunky way, just pass Nothing's to it an add some IsNothing checks to
the handler if you are referencing the "sender" or "e" parameters
currently.
 
S

ShaneO

Rich said:
Private Sub btnMoveNext_Click(...) Handles btnMoveNext.Click

If I call btnMoveNext_Click -- that won't interfere with the Handles part?
I guess I am going to find out.

Just use -

btnMoveNext.PerformClick()


ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.
 
H

Herfried K. Wagner [MVP]

RickH said:
Like other said calling the click event function directly is least
clunky way, just pass Nothing's to it an add some IsNothing checks to
the handler if you are referencing the "sender" or "e" parameters
currently.

I'd pass 'EventArgs.Empty' or a proper 'MouseEventArgs' instance instead of
'Nothing' because it's *very* uncommon that the parameters' values are
'Nothing'.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top