TTIWDBAdvWebGrid cell colours

How do I change the colour of a cell based on each row cell data values?

TIA

ZSL

You can use the OnGetCellProp for this. This event is triggered for every cell rendered. Via the event parameters you can set the color of the cell.

Example:



procedure TIWForm1.TIWAdvWebGrid1GetCellProp(Sender: TObject; RowIndex,
  ColumnIndex: Integer; AValue: string; var AColor: TIWColor;
  var AAlignment: TAlignment; Font: TIWFont);
begin
  if length(TIWAdvWebGrid1.Cells[ColumnIndex, RowIndex]) > 10 then
  begin
    AColor := clRed;
    Font.Style := [fsBold];
    Font.Color := clWhite;
  end;
end;

Tx

Sorry, I spoke too soon.

 
Your solutions works fine for TIWAdvWebGrid but NOT the DB Grid...
 
... I still need help

For a TIWDBAdvWebGrid please use the AValue parameter of the GetCellProp event instead of the Cells property.


Example:
procedure TIWForm5.TIWDBAdvWebGrid1GetCellProp(Sender: TObject; RowIndex,
  ColumnIndex: Integer; AValue: string; var AColor: TIWColor;
  var AAlignment: TAlignment; Font: TIWFont);
begin
  if AValue = '4' then
    AColor := clWebRed;
end;

Okay. What I implemented is:

procedure TIWForm5.TIWDBAdvWebGrid1GetCellProp(Sender: TObject; RowIndex,
  ColumnIndex: Integer; AValue: string; var AColor: TIWColor;
  var AAlignment: TAlignment; Font: TIWFont);
begin
  if ColumnIndex <> [the_ColumnCell_to_color] then
    exit;
  if AValue = '4' then
    AColor := clWebRed;
end;
 
...but when I select a row and select another row without making the first row current then the cell colour is cleared. A refresh of the grid dataset is required to restore the cell colors.
 

... another related question.

 
How can I control the db grid column button font sie and font color?

Are you using MouseSelect := msRow or a similar setting to select rows in the grid?
This setting uses the SelectColor property value to change the background color of the row when it's selected.

It's unfortunately not supported to use the SelectColor and AColor parameter at the same time.
Please set the SelectColor to clNone to avoid this problem.
However you should still be able to use the SelectFontColor as an indicator for the selected row.

1) Assign a value to the Column.CellClass property

Example:

Column.CellClass := 'cellclass';

2) Then add the following CSS code to the page:

.cellclass input
{
color:red;
font-size:16pt;
}
(You can use the (TMS TTIWClientCode control with CodeType set to ctCSS to add CSS to a page)