我现在用DATAGRID控件显示了一张表的数据,期中有一列是数字,我想实现这些数字>50的用红色字体显示,<50的用绿色字体显示,请问各位高手应该如何实现,强调一点是WINFORM中。最好就我的这个例子给出代码,谢谢了。

解决方案 »

  1.   


    int tmp = 0;    //取数字
    for(int i = 0; i < dg.Rows.Count; i++)
    {
        tmp = int.Parse(dg.Rows[i].Cells["数字列"].ToString());
        if(tmp > 50)
        {
            ((DataGridViewTextBoxColumn)dg.Rows[i].Cells["数字列"]).ForeColor = Color.Red;
        }
        else
            ........  = 绿色;
    }_________________________________  仅提供思路作为参考!!  多看看MSDN类库.继承..
      

  2.   


    这样就行了以前做过一次,是用drawing画上去的,那个很慢
    现在想想有简单的办法的
      

  3.   

    http://www.ouaox.cn/index.php?9670-1.html
      

  4.   

    设置DataGridColoredTextBoxColumn
    参考
    参考
      

  5.   

    谢谢各位了,解决了,我改写了下代码
                float tmp = 0;
                for (int i = 0; i < dataGridView1.Rows.Count; i++)
                {
                    float tmp = float.Parse(dataGridView1.Rows[0].Cells[1].Value.ToString());
                    
                    if (tmp > 50)
                    {
                        dataGridView1.Rows[i].Cells[1].Style.ForeColor = Color.Red;                }
                }
    谢谢各位的启发