1

I have a cxGrid where I change the background color of some fields based on values in some of the fields. This is all working very fine. But if I cahnge something in the grids data, the colors aren't updated before I close an reopen my form.

What procedure to call to get this updated if the record is changing?

OZ8HP
  • 1,443
  • 4
  • 31
  • 61
  • 1
    Did you ask the vendor? http://www.devexpress.com/Support/Center/ – David Heffernan Sep 18 '12 at 09:03
  • there are a lot of procedures like .UpdateXXX or .InvalidateXXX – Arioch 'The Sep 18 '12 at 12:07
  • 1
    What event are you using to make the color change? The OnGetContentStyle for either the row or the item usually will do the trick. – Sam M Sep 18 '12 at 15:14
  • 1
    @David Heffernan My experience is that it many times are quicker to ask here (and isn't that what this site is all about - asking questions that others might have a soulution for?) – OZ8HP Sep 19 '12 at 06:03
  • @Sam M I use ...StylesGetContentStyle(Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord; AItem: TcxCustomGridTableItem; out AStyle: TcxStyle); for setting the color and it work OK but if data is changing I need some sort of refresh that updates the colors. – OZ8HP Sep 19 '12 at 06:06
  • I can only repeat that in my experience of QuantumGrid displaying content of TClientDataSet it refreshes styles when database switches rows. Maybe you can use fake Edit/Post cycle to trigger that as well. Or maybe you can send some notifications to TDataSource. But did you tried InvalidateXXX functions ? – Arioch 'The Sep 19 '12 at 07:19
  • @Arioch I think I have tried almost ever Invalidate I can locate (beside the one that works) but so far no luck. To explain what I do: I have this one form with a grid showing some customer data and from this I can press a button to create some other data in another form. This second form updates some data in the table that form 1 is showing and the data is updated OK but the style dosn't and that is what I would like to force it to without having to close and reopen the form. – OZ8HP Sep 19 '12 at 08:12
  • What I have tried now is to have the second form broadcast a message that tells the first form to refresh its data when form 2 is changing them (I use messages a lot in my apps) - and now the color is updating. That is very strange I think because the data was showing OK also before. – OZ8HP Sep 19 '12 at 08:31

3 Answers3

2

To my experience it does update when you switch the row. But i used it in DB-mode with TClientDataSet.

Check methods like

  • TcxControl.InvalidateRect
  • TcxControl.InvalidateRgn
  • TcxControl.InvalidateWithChildren

You can also invalidate node:

  • TcxGrid.ActiveView.Invalidate;
  • TcxGrid.ViewData.Records[0].Invalidate;
  • TcxGridViewData.Rows[0].Invalidate
  • TcxCustomGridTableController.FocusedRecord.Invalidate;

Events like

  • TcxCustomGridTableViewStyles.OnGetContentStyle
  • TcxCustomGridTableItem.OnCustomDrawCell

also exposes those items (with their Invalidate methods) among or inside parameters, like

  • ARecord: TcxCustomGridRecord;
  • ViewInfo -> TcxGridTableCellViewInfo.GridRecord

In other words - open the cxTL unit and grep for "invalidate" word and note every match.

Arioch 'The
  • 15,799
  • 35
  • 62
1

If your grid is attached to a data set, and the data in the dataset changes, the OnGetContentStyle events are called automatically. Make sure that your dataset knows that the data is updated. It sounds like your editing form isn't telling the grid dataset to refresh itself. You can do that either with a callback procedure or implementing the Observer Pattern.

The following code demonstrates how to implement an OnGetContentStyle event for a grid column.

procedure TFormWithGrid.cxGrid1DBTableView1LASTNAMEStylesGetContentStyle(
  Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord;
  AItem: TcxCustomGridTableItem; var AStyle: TcxStyle);
begin
  if ARecord.Values[cxGrid1DBTableView1FIRSTNAME.Index] = 'test' then
  begin
    AStyle := TcxStyle.Create(nil);
    AStyle.Color := clRed;
    AStyle.Font.Style := [fsBold];
  end;
end;
Community
  • 1
  • 1
Sam M
  • 4,136
  • 4
  • 29
  • 42
0

in my situation, this will works cxGridDBTblVwContenido.DataController.Refresh;