首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >更改C# WinForms中网格单元格的颜色

更改C# WinForms中网格单元格的颜色
EN

Stack Overflow用户
提问于 2021-06-03 11:50:02
回答 1查看 462关注 0票数 1

我知道如何在标准DataGridView上这样做,例如:DataGridView.Rows[i].Cells[j].Style.ForeColor = Color.Red;。如何在C1TrueDBGrid (或TrueDBGrid)上对ComponentOne库进行同样的操作?(不使用事件)。我尝试了很多方法,包括

代码语言:javascript
复制
DetailTGrid.Rows[i].Cells[j].Style.ForeColor = Color.Red;
DetailTGrid[i, j].Style.ForeColor = Color.Red;
DetailTGrid.Columns[j].Rows[i].Style.ForeColor = Red;

但什么都不管用。编辑:嗯,或者至少如何改变整条线的颜色?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-06-04 06:14:53

感谢每一个回复的人。解决了问题,不得不使用事件。

使用FetchCellStyle事件。

FetchCellStyle -每当要呈现单元格且C1DisplayColumn.FetchStyle为真时,都会发生。

以下是代码:

代码语言:javascript
复制
private void DetailTGrid_FetchCellStyle(object sender, FetchCellStyleEventArgs e)
{
    decimal sum = 0;

    for (int i = 0; i <= DetailTGrid.RowCount - 1; i++)
    {
        sum = Convert.ToDecimal(DetailTGrid[i, 4]) * Convert.ToDecimal(DetailTGrid[i, 6]);

        if (sum != Convert.ToDecimal(DetailTGrid[i, 9]))
        {
            e.CellStyle.ForeColor = Color.Red;
        }
    }        
}

默认情况下,FetchCellStyle将被禁用,不会被调用。要使FetchCellStyle工作,必须将所需的FetchCellStyle列的FetchStyle属性设置为True

如何打开它:http://helpcentral.componentone.com/docs/c1truedbgrid/disablingeditinginaspecifiedtruedbgridcell.htm

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67820951

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档