2012-09-18 75 views
1

我有一個cxGrid,我根據某些字段中的值更改某些字段的背景顏色。 這是所有工作非常好。但是,如果我在網格數據中加入某些東西,則在關閉重新打開表單之前,顏色不會更新。在cxGrid中刷新顏色

如果記錄更改,要調用哪個過程來更新此過程?

+1

你問過供應商嗎? http://www.devexpress.com/Support/Center/ –

+0

有許多程序,如.UpdateXXX或.InvalidateXXX –

+1

您使用什麼事件來改變顏色?行或項目的OnGetContentStyle通常都會起作用。 –

回答

2

根據我的經驗,它切換行時會更新。但我用TClientDataSet在DB模式下使用它。

檢查方法,如

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

您也可以無效節點:

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

活動等

  • TcxCustomGridTableViewStyles.OnGetContentStyle
  • TcxCustomGridTableItem.OnCustomDrawCell

還公開的那些項目(以及它們的Invalidate方法)之間或內部的參數,如

  • AReco rd:TcxCustomGridRecord;
  • ViewInfo - > TcxGridTableCellViewInfo.GridRecord

換句話說 - 打開cxTL單元和grep爲 「無效」 字樣,並注意每一場比賽。

+2

OP在討論** cxGrid **,而不是cxList。 ;-) –

+0

該死的,我無法讓我的經驗匹配幫助文件 - 我看錯了組件:-) –

1

如果您的網格附加到數據集,並且數據集中的數據發生更改,則會自動調用OnGetContentStyle事件。確保您的數據集知道數據已更新。這聽起來像你的編輯表單不告訴網格數據集自己刷新。您可以通過回調程序或執行Observer Pattern來完成此操作。

以下代碼演示瞭如何爲網格列實現OnGetContentStyle事件。

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;