When I execute the following code:
myleaserow.Cells[5].Value = ((decimal)(myleaserow.Cells[8].Value) * (decimal)(myequiprow.Cells[1].Value)) / 1000;
I get an Object referance not set to an instance of an object error.
How do I fix this
The purpose of doing this is so that I may edit the cell in the datagridview and then insert it into the database. What is strange is that after updating, the error message pops up, but if I choose to continue the new value is displayed. However, the changes are not forwarded to the database.
Is there another way of accomplishing the same task
Thank You,
Protecyon

DataGridView Error
Nilesh Trivedi
The code that was giving me the error turned out to be:
for (int i = 0; i < this.eDataGridView.Rows.Count; i++)
{
}
It should have been:
for (int i = 0; i < this.eDataGridView.Rows.Count-1; i++)
{
}
A classic mistake.
However, I have another question about the following code:
for (int i = 0; i < this.eDataGridView.Rows.Count - 1; i++)
{
lrow = lDataGridView.Rows[i];
erow = eDataGridView.Rows[i];
if (lrow.Cells["1"].Value.ToString() != "" && erow.Cells["2"].Value.ToString() != "" && lrow.Cells["3"].Value.ToString()!="")
{
lrow.Cells["4"].Value = (((decimal)lrow.Cells["1"].Value * (decimal)erow.Cells["2"].Value)/1000)+(decimal)lrow.Cells["3"].Value;
}
}
The purpose of the code is to fill in cell 4 within row l after it has sufficient information. The information however does not become available right away as the user first types in information in cell 1 and 3 in lrow, and then types in information for cell 2 in erow. Only then can cell 4 in lrow be filled in.
However, I am looking for a better way of accomplishing this, since this method is run right before the update method, and consumes a lot of resources since it transverses all rows even those that might have already been filled in.
Would the best way of accomplishing this task be through the CellChangedEvent, in which I would check whether the user has changed one of the cells that I am interested in, and then to go and check whether the rest of the cells that I am interested in have also changed. Then I could fill in cell 4 in lrow if I have sufficient information. Of course if I do not have sufficient information I can prompt the user to enter it at this point. Or is there a better way
Hallo2ooo
regards
prathvi