-2

Hello I have been struggling trying to get the event to trigger based on the object that it is passed.... I am not sure if that's how it should be worded but you guys can take a look at the book and give me some insight

I am making a datagrid form, inside this form, there's a function

private void (List<string> listProducts>
{
    foreach (aProduct in listProducts)
            {
                // reset row data
                rowProduct = new string[10];
                // add the row
                this.dataDisplay.Tables["ProductData"].Rows.Add(rowProduct);
                double checkingresult;
                checkingresult = checkDiameter(aProduct);
}

Inside this form there's a function that would check the validity of the test product, so checkingresult would return 0 or 1

Then I created an event button to click on to change the color of the cell in the datagrid when it is clicked


     private void bttnChecking_Click(object sender, EventArgs e)
        {


            DataGridViewCellStyle style = new DataGridViewCellStyle();
            style.Font = new Font(datagridProductData.Font, FontStyle.Bold);
            style.BackColor = Color.Red;
            style.ForeColor = Color.White;

            foreach (aProduct in ListProducts)
            {

            }
                for (int i = 0; i < RowCount - 1; i++)
            {
                Rows[i].Cells[5].Style = style;

            }
        }
    }

my question is, how do I pass the "checkingresult" into the event to change the color when it returns 0 or 1. Pls halp

Phong
  • 1
  • 1
  • 1
    Your first code snippet is not valid. `private void (List listProducts>` –  Feb 14 '20 at 22:22

1 Answers1

-2

without seeing the function I am assuming that it returns the value of either 1 or 0. If it does then check for the result before this line:

DataGridViewCellStyle style = new DataGridViewCellStyle();

something like this:

 string result = foo(null);
 DataGridViewCellStyle style = new DataGridViewCellStyle();

Provided your function returns a value as I am only assuming.

 static string foo(string Status)
{
   {
    string result = "0";
    return result;
   }
}