Change the color of the Grid Cell in C# WinForms

1k Views Asked by At

I know how to do this on a standard DataGridView, for example: DataGridView.Rows[i].Cells[j].Style.ForeColor = Color.Red; . How to do the same on C1TrueDBGrid (or TrueDBGrid) from ComponentOne library? (without using events). I tried many ways, including

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

But nothing works. edit: Well, or at least how to change the color of the entire line?

1

There are 1 best solutions below

1
Miko On BEST ANSWER

Thanks to everyone who responded. Solved the problem and had to use event.

Used the FetchCellStyle event.

FetchCellStyle - Occurs whenever a cell is to be rendered and the C1DisplayColumn.FetchStyle is true.

Here is the code:

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;
        }
    }        
}

By default, FetchCellStyle will be disabled and will not be called. For FetchCellStyle to work, you must set the FetchStyle property for the desired column to True.

How to turn it on: http://helpcentral.componentone.com/docs/c1truedbgrid/disablingeditinginaspecifiedtruedbgridcell.htm