I have two datagridview that each contain two columns and the same numbers of rows.I compared these two datagridview using this loop :
int result = 0;
for (int i=0;i< dgvInvent1.RowCount;i++)
{
var src1 = dgvInvent1.Rows[i].Cells[1].Value.ToString();
var src2 = dgvInvent2.Rows[i].Cells[1].Value.ToString();
result = Int32.Parse(src1) - Int32.Parse(src2);
}
I want to transfer the result to another datagridview too, I named it "dgvFinal" , except that dvgFinal is in another form called "Form2" that I just created , so i added this line to form2
public DataGridView dvgFinal { get; set; }
and in my main Form i added to my loop
Form2 re = new Form2();
int result = 0;
for (int i=0;i< dgvInvent1.RowCount;i++)
{
var src1 = dgvInvent1.Rows[i].Cells[1].Value.ToString();
var src2 = dgvInvent2.Rows[i].Cells[1].Value.ToString();
result = Int32.Parse(src1) - Int32.Parse(src2);
re.dvgFinal.Rows[i].Cells[2].Value = result;
}
but it doesn't work , i get
System.NullReferenceException was unhandled
HResult=-2147467261
Message=Object reference not set to an instance of an object.
someone could help me ? Thank you in advance