深圳全飞鸿
标题:
DataGridView 改变行列颜色
[打印本页]
作者:
zhgc
时间:
2020-12-17 14:38
标题:
DataGridView 改变行列颜色
未验证:
private void ChangBackColor()
{
if (dataGridView1.Rows.Count > 0)
{
foreach (DataGridViewRow row in dataGridView1.Rows)
{
if (row.Cells["列名"].Value.ToString() == "条件")
{
row.Cells["列名"].Style.ForeColor = System.Drawing.Color.Red;
row.DefaultCellStyle.ForeColor = Color.Red; //改变整行的
}
}
DataGridViewCellStyle dgvcs = new DataGridViewCellStyle();
dgvcs.BackColor = Color.Green;
dataGridView1.Columns["列名"].DefaultCellStyle = dgvcs; //整列
}
}
复制代码
欢迎光临 深圳全飞鸿 (http://www.nagomes.com/disc/)
Powered by Discuz! X3.2