how to call a control's event?

In my form_load function;

I want to call

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{

}

how to do that

Thank you



Answer this question

how to call a control's event?

  • KevinFreeman

    So you want to call that function from your form’s constructor without explicitly raising the event that causes that function

    Does it use either the sender or e values being passed in If not it is as simple as:

    comboBox1_SelectedIndexChanged(null, null);

    Otherwise you may want to pass in a reference to the calling object and an empty EventArgs object ala:

    comboBox1_SelectedIndexChanged(this, new EventArgs());

    Does this work for you



  • Hang Lam

    Simply, if you have

    private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
    {

    // My code is here

    }

    change it to

    private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
    {

    MyAction();

    }

    private void MyAction()

    {

    // My code is here

    }

    and call MyAction() in form_load func.



  • how to call a control's event?