给DatagridView 设置 列和行 的标题背景色 怎么没有效果?????
foreach (DataGridViewRow row in dataGridView1.Rows )
{
if (Convert.ToInt32(row.Cells["Emp_Age"].Value) < 18 && Convert.ToInt32(row.Cells["Emp_Age"].Value)>=1)
{
row.HeaderCell.Style.BackColor = Color.Red;
row.Cells["Emp_Age"].Style.BackColor = Color.Red;
dataGridView1.Columns[row.Cells["Emp_Age"].ColumnIndex].HeaderCell.Style.BackColor = Color.Red;
row.Cells["Emp_Age"].Style.Font = new Font(dataGridView1.Font, FontStyle.Bold);
row.Cells["Emp_Age"].Style.Alignment = DataGridViewContentAlignment.MiddleRight; }
} 高手指点!!!!
foreach (DataGridViewRow row in dataGridView1.Rows )
{
if (Convert.ToInt32(row.Cells["Emp_Age"].Value) < 18 && Convert.ToInt32(row.Cells["Emp_Age"].Value)>=1)
{
row.HeaderCell.Style.BackColor = Color.Red;
row.Cells["Emp_Age"].Style.BackColor = Color.Red;
dataGridView1.Columns[row.Cells["Emp_Age"].ColumnIndex].HeaderCell.Style.BackColor = Color.Red;
row.Cells["Emp_Age"].Style.Font = new Font(dataGridView1.Font, FontStyle.Bold);
row.Cells["Emp_Age"].Style.Alignment = DataGridViewContentAlignment.MiddleRight; }
} 高手指点!!!!
private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
this.dataGridView1.ColumnHeadersDefaultCellStyle.BackColor = Color.Red;
}
//改变标题栏颜色