DataGridView中更改单元格背景颜色 [英] DataGridView changing cell background color

查看:1039
本文介绍了DataGridView中更改单元格背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

private void dgvStatus_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
{
    foreach (DataGridViewRow row in dgvStatus.Rows)
    {
        row.Cells[color.Index].Style.BackColor = Color.FromArgb(((GesTest.dsEssais.FMstatusAnomalieRow)row.DataBoundItem).iColor);
    }
}



我尝试设置各个背景颜色从背景颜色列单元。这不起作用的颜色永远不会改变。任何想法,为什么呢?

I'm try to set the background color of each cell from the background color column. this doesn't work the color never change. Any idea of why?

我一直在四处寻找,但没有发现任何有用的。

I've been looking around but didn't found anything usefull

推荐答案

我终于得到它的工作。下面的代码:

I finally managed to get it working. Here the code :

private void dgvStatus_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
    if (e.ColumnIndex != color.Index)
        return;

    e.CellStyle.BackColor = Color.FromArgb(int.Parse(((DataRowView)dgvStatus.Rows[e.RowIndex].DataBoundItem).Row[4].ToString()));
}

如果有谁知道一个更好的做到这一点,请不要犹豫,它张贴。我接受建议

if anyone know a better to do this please don't hesitate to post it. I'm open to suggestion

这篇关于DataGridView中更改单元格背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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