【问题标题】:Change the color of the Grid Cell in C# WinForms在 C# WinForms 中更改网格单元格的颜色
【发布时间】:2021-06-03 11:50:02
【问题描述】:

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

DetailTGrid.Rows[i].Cells[j].Style.ForeColor = Color.Red;
DetailTGrid[i, j].Style.ForeColor = Color.Red;
DetailTGrid.Columns[j].Rows[i].Style.ForeColor = Red;

但是没有任何效果。编辑:嗯,或者至少如何改变整行的颜色?

【问题讨论】:

    标签: c# visual-studio winforms datagridview componentone


    【解决方案1】:

    感谢所有回复的人。解决了问题,不得不使用事件。

    使用了 FetchCellStyle 事件。

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

    代码如下:

    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 起作用,您必须将所需 FetchStyle 属性设置为 True

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

    【讨论】:

    • 嗨,@Miko。这个解决方案能解决您的问题吗?如果解决了,您可以单击“✔”接受它作为答案。有助于社区成员解决类似问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-05-03
    • 1970-01-01
    • 2017-06-29
    • 1970-01-01
    • 2019-12-13
    • 1970-01-01
    • 2014-08-24
    相关资源
    最近更新 更多