prabha haran

prabha haran

  • NA
  • 81
  • 30.3k

how to change a row color in grid based on condition

Apr 3 2017 1:02 AM
 in windows form i have a grid in that i have two column if avilable quantity is less than minimum qty i have make the row as red
 
my code is
 
public void SelectStockAvailblity()
{
try
{
DataSet ds = stockDAL.Rawmaterialselect(stockBAL);
if (ds.Tables[0].Rows.Count >= 0)
{
dgvStockAvailabilityList.DataSource = ds.Tables[0];
for(int i=0;i<ds.Tables[0].Rows.Count;i++)
{
foreach (DataGridViewRow row in dgvStockAvailabilityList.Rows)
{
//if (Convert.ToInt64(ds.Tables[0].Rows[0]["Available Quantity"]) < Convert.ToInt64(ds.Tables[0].Rows[0]["Minimun Quantity"]))
//{
var minquty = ds.Tables[0].Rows[i]["Minimun Quantity"].ToString();
var totalqty = ds.Tables[0].Rows[i]["Available Quantity"].ToString();
if (Convert.ToInt64(row.Cells[2].Value) < Convert.ToInt64(row.Cells[3].Value!=null))
{
this.dgvStockAvailabilityList.DefaultCellStyle.ForeColor = Color.Red;
//this.dgvStockAvailabilityList.Rows[i].DefaultCellStyle.ForeColor = Color.Red;
}
else
{
dgvStockAvailabilityList.CurrentCell.Style.ForeColor = Color.Beige;
}
}
//}
}
//this.dgvStockAvailabilityList.Columns["Miscellaneous Quantity"].Visible=false;
//this.dgvStockAvailabilityList.Columns["EmpId"].Visible = false;
}
else
{
// MessageBox.Show("No records found");
}
}
 

Answers (1)