DGV_Left.AutoGenerateColumns = false;
            DGV_Left.DataSource = ds.Tables[0];
            DGV_Left.Refresh();
datagridview 控件如上绑定了数据后其中某列是价格
我现在想要做的是,如果根据绑定出来的值的大小来改变这个价格字体的颜色
如绑定出来的是
价格
2  黑色
3  黑色
3  黑色
4  绿色字体显示
5  绿色字体显示
6  红色字体显示该如何处理?

解决方案 »

  1.   

    楼主 google 下 值 颜色 datagridview有很多文章的,还可以在行前面根据值的大小加不同的图标
      

  2.   


    int i = dataGridView1.Rows[1].Cells[0].value;//传来的值;
    if(i<20)//20假设你判断的值
    {
      dataGridView1.Rows[1].Cells[0].Style.ForeColor = System.Drawing.Color.Red;
    }
    else
    {
      //类似做法
    }
      

  3.   

    int i = dataGridView1.Rows[1].Cells[0].value;//传来的值;
    if(i<20)//20假设你判断的值
    {
      dataGridView1.Rows[1].Cells[0].Style.ForeColor = System.Drawing.Color.Red;
    }
    else
    {
      //类似做法
    }楼上说的应该是对的  可以试试
      

  4.   

    我要的是绑定的时候判断
    而不是已知哪个单元格
    因为我datagridview绑定出来的行数不定,数据也不定
    如果我用for 去遍历datagridview所有行的单元格那肯定可以实现
    我的问题在判定数据的时候去判断并改变现实的颜色
    就像asp.net 的rowdatabound的事件一样。
      

  5.   

    dataGridView1.Rows[1].Cells[0].Style.ForeColor = System.Drawing.Color.Red;
      

  6.   

    大部分都是误导,使用cellformating处理吧
      

  7.   

            private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
            {
                if (dataGridView1.Columns[e.ColumnIndex].Name == "")
                {
                    if (e.Value != null)
                    {
                        e.CellStyle.BackColor = Color.Red;
                    }
                    else
                    { }
                }
            }自己改改吧