|
-
November 12th, 2008, 06:41 PM
#1
Simulated button click
Hi
I have a window that has a grid, initial requirements were for the grid to be empty till a calculate button was clicked. I now need to fill this grid when the window is instantiated. Instead of repeating the code in the button I need to either call that method or simulate a click on the button so it will fill the gridinitially. Can anyone help me with either a simulated click on the button or calling that method programatically. The name of the method is
public void executeButton_Click(object sender, EventArgs e)
Thanks
-
November 12th, 2008, 06:46 PM
#2
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?
-
November 12th, 2008, 09:25 PM
#3
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
}
-
November 13th, 2008, 01:00 AM
#4
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.
Regards,
MMH
Rate my post if you find it usefull. 
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|