CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2008
    Posts
    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

  2. #2
    Join Date
    Jun 2008
    Posts
    2,477

    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?

  3. #3
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    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
    }

  4. #4
    Join Date
    Jan 2006
    Location
    18° 32' N / 73° 52' E
    Posts
    416

    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
  •  





Click Here to Expand Forum to Full Width

Featured