Click here to Skip to main content
15,905,316 members

Comments by Member 11302407 (Top 2 by date)

Member 11302407 3-Mar-18 12:05pm View    
Also now by this code I am getting exception object reference not set to an instance.
Member 11302407 3-Mar-18 11:58am View    
this is my code where i am using .

if (dataGridView1.Rows.Count > 0)
{

DataTable dt = dataGridView1.DataSource as DataTable;
//Check if the product Id exists with the same Price
foreach (DataGridViewRow row in dataGridView1.Rows)
{
dataGridView1.AllowUserToAddRows = true ;
if (Convert.ToString(row.Cells[1].Value) == tb_ino.Text )
{
//Update the Quantity of the found row
MessageBox.Show("matched!");
//row.cells[3] is value for qty
//multiply this to row.cells[4]
row.Cells[3].Value = Convert.ToString(Convert.ToInt16(tb_qty.Text) + Convert.ToInt16(row.Cells[3].Value));
row.Cells[5].Value=(Convert.ToInt16(row.Cells[3].Value) * Convert.ToInt16(row.Cells[4].Value)).ToString();
dataGridView1.DataSource = dt;
found = true;
}

}
if (!found)
{
dataGridView1.AllowUserToAddRows = true;


//Add the row to grid view
dt.Rows.Add(dataGridView1.RowCount, r[0], r[1], tb_qty.Text.Trim(), r[4], price);
dt.AcceptChanges();
dataGridView1.DataSource = dt;

}

}