1

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?

Vy Do
  • 46,709
  • 59
  • 215
  • 313
Miko
  • 11
  • 3

1 Answers1

0

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

Miko
  • 11
  • 3
  • Hi, @Miko. Does this solution solve your problem? If it is solved, you can click ‘✔’ to accept it as an answer. It is helpful for community members to solve the similar problems. – Hui Liu-MSFT Jun 28 '21 at 08:55