改变细胞颜色 [英] Change Cell Color

查看:68
本文介绍了改变细胞颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我的代码将循环遍历我的DGV行,如果找到请求的字符串,则单元格颜色应该更改。


但是,有时需要多次调用代码才能使单元格更改生效。


任何想法?


谢谢!

 foreach(myDataGridView.Columns中的DataGridViewColumn col)
{
foreach(myDataGridView.Rows中的DataGridViewRow行)
{
if (row.Cells [col.Name] .Value!= null)
{
if(row.Cells [col.Name] .Value.ToString()。IndexOf(TextToFind,StringComparison.InvariantCultureIgnoreCase)! = -1)
{
//突出显示单元格
row.Cells [col.Name] .Style.BackColor = Color.LightYellow;
}
}
}
}



解决方案

< blockquote>

看看这个MSDN帮助。我认为这就是你要找的东西:


http:/ /msdn.microsoft.com/en-us/library/1yef90x0.aspx


Hi,

My code below will loop through my DGV rows and if the requested string is found the cell color should change.

However, sometimes the code needs to be called multiple times for cell change to take effect.

Any ideas?

Thanks!

foreach (DataGridViewColumn col in myDataGridView.Columns)
            {
                foreach (DataGridViewRow row in myDataGridView.Rows)
                {
                    if (row.Cells[col.Name].Value != null)
                    {
                        if (row.Cells[col.Name].Value.ToString().IndexOf(TextToFind, StringComparison.InvariantCultureIgnoreCase) != -1)
                        {
                            // highlight cell
                            row.Cells[col.Name].Style.BackColor = Color.LightYellow;
                        }
                    }
                }
            }


解决方案

Have a look at this MSDN Help. I think it's what you're looking for:

http://msdn.microsoft.com/en-us/library/1yef90x0.aspx


这篇关于改变细胞颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆