C# Datagridview行更改颜色
我正在制作一个库存系统,每3秒钟它会检查第5单元中的行,如果它低于10。那么我的问题是如何将颜色改为红色,使其低于10C# Datagridview行更改颜色,c#,visual-studio-2010,C#,Visual Studio 2010,我正在制作一个库存系统,每3秒钟它会检查第5单元中的行,如果它低于10。那么我的问题是如何将颜色改为红色,使其低于10 private void belowstock() { int row; int qty, qtyOnHand; for (row = 0; row < dataGridView1.RowCount; row++) { qty = int.Parse(dataGridView
private void belowstock()
{
int row;
int qty, qtyOnHand;
for (row = 0; row < dataGridView1.RowCount; row++)
{
qty = int.Parse(dataGridView1.Rows[row].Cells[5].Value.ToString());
qtyOnHand = 10;
if (qty <= qtyOnHand)
{
//red
}
else
//white
}
}
private void belowstock()
{
int行;
整数数量,qtyOnHand;
对于(行=0;行 如果(数量请在循环中尝试以下代码:
row.DefaultCellStyle.BackColor = Color.Red;
LINQ
如何做到这一点
private void belowstock()
{
dataGridView1.Rows.Cast<DataGridViewRow>().Where(w => (int)w.Cells[5].Value < 10).ToList().ForEach(f => f.DefaultCellStyle.BackColor = Color.Red);
dataGridView1.Rows.Cast<DataGridViewRow>().Where(w => (int)w.Cells[5].Value > 10).ToList().ForEach(f => f.DefaultCellStyle.BackColor = Color.White);
}
private void belowstock()
{
dataGridView1.Rows.Cast().Where(w=>(int)w.Cells[5]。Value<10.ToList().ForEach(f=>f.DefaultCellStyle.BackColor=Color.Red);
dataGridView1.Rows.Cast().Where(w=>(int)w.Cells[5].Value>10.ToList().ForEach(f=>f.DefaultCellStyle.BackColor=Color.White);
}
只需输入此代码即可您的Datagridview是否绑定此winforms Datagridview是吗?是否要更改整行颜色或特定单元格颜色?@Co.Aden抱歉,先生,盲显是什么意思?@Junaith是的,先生。我希望第5单元格中的整行低于10。@DontStopLearning-有关较短的内容,请参阅YuriyThank you提供的链接好极了,先生!