Reputation: 21
I have datagridview which is populated with 6 columns product id,product name,features,price,quantity and total price. All product with 0 quantity is automatically removed from the datagridview. My questions is how do I change color of the cell in "Quantity" if:
Please bear with me as I am new to programming. I am required to do this for the inventory system we made for our capstone project.
Many thanks!
Upvotes: 0
Views: 3356
Reputation: 2062
you must first foreach on data grid view rows like following :
foreach (DataGridViewRow Myrow in dataGridView1.Rows)
then foreach on cell
foreach(DataGridViewCell cell in Myrow.Cells)
and then convert cells data to int32 and then use DefaultCellStyle.BackColor
foreach (DataGridViewRow Myrow in dataGridView1.Rows)
{
foreach(DataGridViewCell cell in Myrow.Cells)
{ if (Convert.ToInt32(cell.Value)<10)
Myrow .DefaultCellStyle.BackColor = Color.red;
else if(Convert.ToInt32(cell.Value)<20)
Myrow.DefaultCellStyle.BackColor = Color.orange;
}
}
Upvotes: 2