发现用了着色功能,网格显示很慢,占CPU高。
dg.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.Cyan;前景色也是一样。

解决方案 »

  1.   

    另外在行绘制时着色应当可以效率高些,在RowPostPaint 事件中着色。
      

  2.   

    DataGridViewCellStyle 
    不使用颜色,速度如何
      

  3.   

    void dg.CellPainting()
    {
        //才几行数据,[不使用颜色]或[只对IsChk着色]很快/米
        //1 这样很直观,但很慢。
        if ((bool)r["IsChk"]) dg.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.Cyan; //确认
        if ((bool)r["IsApv"]) dg.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.DarkCyan; //审核
    米/    //2 改为这样就不慢了
        if ((bool)r["IsApv"]) //是否已审核
        {
            dg.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.DarkCyan;
        }
        else
        {
            if ((bool)r["IsChk"]) //是否已确认
            {
                dg.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.Cyan;
            }
        }
    }
    在第1种方法中,是不是在付DefaultCellStyle值的时候CellPainting嵌套了?
      

  4.   

    //看来真是CellPainting嵌套了
    //这样直观,速度也快了
    DataGridViewCellStyle sty=new DataGridViewCellStyle();
    if ((bool)r["IsChk"]) { sty.BackColor = Color.Cyan; }
    if ((bool)r["IsApv"]) { sty.BackColor = Color.DarkCyan; }
    dg.Rows[e.RowIndex].DefaultCellStyle = sty;