Call Contentclick event elsewhere

62 Views Asked by At

I have a method inside the CellContentClick event handler to filter data as shown below:

private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
    if (cboQuantity.Text == "1")
    {
        tempn = 4;
    }

    if (cboQuantity.Text == "2")
    {
        tempn = 5;
    }

    if (cboQuantity.Text == "3")
    {
        tempn = 6;
    }

    if (cboQuantity.Text == "4")
    {
        tempn = 7;
    }

    if (cboQuantity.Text == "5")
    {
        tempn = 8;
    }
    DataGridViewRow row = this.dataGridView1.Rows[e.RowIndex];
    txtN.Text = row.Cells[tempn].Value.ToString();

Unfortunately when I move this code it won't work in other methods because it depends on the DataGridViewCellEventArgs and when I call them the method greys out and won't work

Is there a way I can signal this method (for example button1.PerformClick on a button)?

1

There are 1 best solutions below

0
On BEST ANSWER

Since this is dependent on an event fired by the DataGridViewCell (in other words, some parts of the method depend on e), you cannot move as is. If you want to use elsewhere, you need to "wrap" it in a method that accepts the same arguments, then pass those arguments to the method.