I used following code to solve the problem:
I use a public function which is called from a button_click event.
public void btnclick(int i)
{
//code to execute in which I use variable i because I need to modify data table on
//specific rows. Each row matches with one button, therefor I need the correct number.
}
private void button1_Click(object sender, EventArgs e)
{
btnclick(1);
}
private void button2_Click(object sender, EventArgs e)
{
btnclick(2);
}
And so on for every button.