习惯了Web中的RowDataBound,写起Winform来发现找不到RowDataBound事件,郁闷,winform中的datagridview事件非常丰富~~  ,找了大半天才找到个能用的事件

        private void dataGridView1_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)
        {
            if (e.RowIndex != -1)
            {
                DataGridViewRow datagridview = dataGridView1.Rows[e.RowIndex];
                try
                {
                    if (bool.Parse(datagridview.Cells["IsExistent"].Value.ToString())== false)
                    {
                        datagridview.DefaultCellStyle.ForeColor = System.Drawing.Color.Blue;  
                    }
                    if (bool.Parse(datagridview.Cells["IsBlock"].Value.ToString())==true)
                    {
                        datagridview.DefaultCellStyle.ForeColor = System.Drawing.ColorTranslator.FromHtml("#e78a29") //自定义颜色

                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }

 

posted on 2008-12-11 09:40  Shannon  阅读(1523)  评论(1编辑  收藏  举报