Press a buton after pressing another button

Jelmer

Regular
Joined
Jan 11, 2006
Messages
96
Hello..

I've got a big problem...

On a form, i have a button called Delete

If i press delete this code runs:

Code:
        private void btnWissen_Click(object sender, EventArgs e)
            //Verwijderen!!
        {
            product.verwijderen(Convert.ToInt16(txtID.Text));
            System.Windows.Forms.Application.DoEvents();
            txtReset_Click(sender, e);
        }

The product is removed (that works).
Than i wait...
Then the code of the button txtReset_Click is runned...

But the last one doestn't do anything...
Also not if i copy and past the code to here...

If i run the program, and after i pushed on Delete, and then on txtReset it works well..

What is wrong????????????
 
It would help if you posted the code from the txtReset_Click method. One thing you may be doing wrong, if you are using the sender object at all in the txtReset_Click event it would work when you click on the txtReset but not when you clicked the btnWissen since you would have passed down the button not the textbox.
 
Ok:

Code:
        private void txtReset_Click(object sender, EventArgs e)
        {
            Productenladen_Load(sender,e);
        }


        private void Productenladen_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'billingMDB.Bedrijven' table. You can move, or remove it, as needed.
            //this.bedrijvenTableAdapter.Fill(this.billingMDB.Bedrijven);
            // TODO: This line of code loads data into the 'billingMDB.FactuurRegels' table. You can move, or remove it, as needed.
            //this.factuurRegelsTableAdapter.Fill(this.billingMDB.FactuurRegels);
            // TODO: This line of code loads data into the 'billingMDB.Producten' table. You can move, or remove it, as needed.
            //this.productenTableAdapter.Fill(this.billingMDB.Producten);
            try
            {
                this.Cursor = Cursors.AppStarting;
                System.Windows.Forms.Application.DoEvents();
                //status.Text = "Klantgegevens inlezen";
                //Klantgegevens laden
                product = new Class_products(0, "", 0, "", 0, 0);
                product.open("SELECT * FROM Producten order by Naam");
                product.read();
                product.first();
                int ex;
                ex = Convert.ToInt16(product.return_id());
                MessageBox.Show(Convert.ToString(ex) + " / " + Convert.ToString(mobiel));         
                mobiel = 0;
                laden();                
            }
            finally
            {
                this.Cursor = Cursors.Default;
                //status.Text = "Gereed";
            }
        }
 
OnClick isn't a method it's an event. What PlausiblyDamp is suggesting is that instead of calling the method attached to the OnClick event (txtReset_Click(sender, e);) you instead call txtReset.PerformClick().
 
I've found the easiest way for me (I get confused sometimes with having handlers floating all around) is to take to the code from Reset and put it in a function.

Call the function from btnWissen_Click & txtReset_Click.... and it looks like txtReset_Click is calling another event (the form load event?).

So, in my simple eyes, that code that you want to call from three different events should just be a function called directly.

In C# I would definately do it this way. In VB.Net I might just as well play with the handlers because I'm more comfortable with vb.net... but I still don't like the idea of multiple procedures handling the same event. Just confuses me on the bookkeeping end.
 
Back
Top