日期:2014-05-18 浏览次数:21458 次
private   void   dataGridView1_RowPrePaint(object   sender,   DataGridViewRowPrePaintEventArgs   e)
                {
                        if   (e.RowIndex   > =   dataGridView1.Rows.Count   -   1)
                                return;
                        DataGridViewRow   dgr   =   dataGridView1.Rows[e.RowIndex];
                        try
                        {
                                if   (dgr.Cells[ "列名 "].Value.ToString()   ==   "比较值 ")
                                {
                                        dgr.DefaultCellStyle.ForeColor   =   设置的颜色;
                                }
                        }
                        catch   (Exception   ex)
                        {
                                MessageBox.Show(ex.Message);
                        }
                }
------解决方案--------------------
你把那列掩藏不就可以了,,显不显示并没关系   
     private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            try
            {
                if (dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString()=="2")
                {
                        e.CellStyle.BackColor = Color.Red;
                }
            }
------解决方案--------------------