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

查看:48
本文介绍了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 am trying 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天全站免登陆