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:
1. If quantity is less than 20 color orange
2. If quantity is less than 10 color red
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!
What I have tried:
I have no idea where to start but this is the code we used for datagrdiview1:
public void GetData()
{
try
{
con = new SqlConnection(cs.DBConn);
con.Open();
String sql = "SELECT Product.ProductID,ProductName,Features,Price,sum(Quantity),sum(Price*Quantity) from Temp_Stock,Product where Temp_Stock.ProductID=Product.ProductID group by Product.productID,productname,Price,Features,Quantity having(Quantity>0) order by ProductName";
cmd = new SqlCommand(sql, con);
rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
dataGridView1.Rows.Clear();
while (rdr.Read() == true)
{
dataGridView1.Rows.Add(rdr[0], rdr[1], rdr[2], rdr[3], rdr[4], rdr[5]);
}
con.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}