习惯了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);
}
}
}