I am adding data in gridview on button click event through following code:
int row = 0;
dataGridView1.Rows.Add();
row = dataGridView1.Rows.Count - 2;
dataGridView1["Description",row].Value = name;
dataGridView1["Quantity", row].Value = qty.Text;
dataGridView1["Price", row].Value = p;
dataGridView1["Discountcell", row].Value = "0000";
dataGridView1["amt", row].Value = tot;
its working perfectly fine.
now i want when I enter discount in
, discount should minus from total amount. for this I have following code:
foreach (DataGridViewRow item in dataGridView1.Rows)
{
int n = item.Index;
dataGridView1["amt", n].Value = tot - float.Parse(dataGridView1.Rows[n].Cells[3].Value.ToString());
}
Here it gives me following error:
An unhandled exception of type 'System.NullReferenceException' occurred in Sales System1.exe
Additional information: Object reference not set to an instance of an object.
without this subtracting code data is added in gridview. but when I put this code it gives above error. What I need to do?
tot?? is it define somewhere?