c# - Datagridview 行改变颜色

标签 c# visual-studio-2010

<分区>

我正在制作一个库存系统,如果它低于 10,它会每 3 秒检查单元格 5 中的行。然后我的问题是如何将颜色更改为红色以显示低于 10 的行。

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
       }
    }

最佳答案

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);
}

把这段代码放上

关于c# - Datagridview 行改变颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21570467/

相关文章:

visual-studio-2010 - Wix HeatFile 任务锁 Dll

c# - 如何获取 Lambda MemberExpression 的值

c# - EF6动态获取表

c++ - 如何按一种度量对元素进行排序

visual-studio - Visual Studio 2010 片段 - 当前日期

c# - Visual Studio 2010 测试未在异常时进入调试器

c# - 我应该在设计中的什么位置放置项目或应用程序范围的 TraceSwitch?

c# - 如何创建树状结构

c# - 如何从图库中挑选的图像中获取文件名?

c++ - 如何使程序成为默认程序以在 Visual Studio C++ 中打开特定文件