Re: Simulated button click
If there is no button, there is no need to hide it and simulate a button click. Why not just subclass the grid and add the code in the constructor?
Re: Simulated button click
Pull the code out of the button and put it into another method:
Code:
public void executeButton_Click(object sender, EventArgs e)
{
FillGrid( );
}
private void FillGrid( )
{
// grid filln' code
}
Re: Simulated button click
One should never code directly under the control event handler. Program logic should be kept separate in methods for the reuse.
As Arjay stated, that is the correct way.
But since you would be interested in knowing how to simulate a click, below is the code for it.
Code:
executeButton_Click(null, null)
Beware, there are lots of potential problems with this, so try to avoid it where ever possible.
At the same time, i could think of some scenarios where you can do this.
Suppose, you have an edit form having cascaded dropdown lists. Here you would like to call the "SelectedIndexChanged" inorder to select the value in the lists.
I hope this helps.