日期:2014-05-17  浏览次数:21092 次

winform datagridview更改选中行中选中单元格的背景或字体颜色
RT,想在datagridview中选中某一行数据的情况下,将鼠标选中的单元格颜色突出显示,请问能不能实现?
一开始使用
C# code
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Selected)
            {
                DataGridViewCell aa = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];
                aa.Style.ForeColor = Color.Red;
                aa.Style.BackColor = Color.LightGreen;
            }
        }

只能实现在不选中改行的情况下颜色突出显示。但是在选中的情况下,选中颜色会将其盖掉,看不出差别

------解决方案--------------------
有没有rowPrePaint事件?
private void dgv_RowPrePaint_1(object sender, DataGridViewRowPrePaintEventArgs e)
{

dgv.Rows[e.RowIndex].Cells["A"].Style.SelectionBackColor = Color.Red;
}