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

datagridview选中单元个更改背景颜色,该怎么解决

2012-04-28 
datagridview选中单元个更改背景颜色datagridview中,将所有值为1的单元格更改背景,我用for循环遍历单元格,

datagridview选中单元个更改背景颜色
datagridview中,将所有值为1的单元格更改背景,我用for循环遍历单元格,最后的结果是最后一个值为1的单元格可以更改。
设置断点调试的结果是:每次遍历到值为1的单元格,更改背景颜色,然后遍历都下一个的时候原来更改的就又变成默认颜色。

请高手帮帮忙,怎样才能让所有值为1 的单元格更改背景颜色 ?


[解决办法]

C# code
        private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)        {            if (dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString() == "1")                e.CellStyle.BackColor = Color.Red;        }
[解决办法]
e.Row.Attributes.Add("onclick", "if(window.oldtr!=null){window.oldtr.runtimeStyle.cssText='';}this.runtimeStyle.cssText='background-color:#e6c5fc';window.oldtr=this");
e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#B2DFEE'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
使用于asp.net IE

热点排行