首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

winform datagridview改动选中行中选中单元格的背景或字体颜色

2013-07-15 
winform datagridview更改选中行中选中单元格的背景或字体颜色RT,想在datagridview中选中某一行数据的情况

winform datagridview更改选中行中选中单元格的背景或字体颜色
RT,想在datagridview中选中某一行数据的情况下,将鼠标选中的单元格颜色突出显示,请问能不能实现?
一开始使用

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;
        }

热点排行