Delphi DevExpress TcxGridDBLayoutViewItem OngetContentStyle不';行不通

Delphi DevExpress TcxGridDBLayoutViewItem OngetContentStyle不';行不通,delphi,styles,devexpress,Delphi,Styles,Devexpress,我使用Devexpress和Delphi xe7 我尝试以不同的方式更改TcxGridDBLayoutViewItem的样式 if AItem.EditValue = 'Discharge' then begin AStyle := cxstylNewDischarge; end else if AItem.EditValue = 'Operation' then begin AStyle := cxstylNewOperation; end el

我使用
Devexpress
Delphi xe7

我尝试以不同的方式更改
TcxGridDBLayoutViewItem
的样式

  if AItem.EditValue = 'Discharge' then
  begin
    AStyle := cxstylNewDischarge;
  end
  else
  if AItem.EditValue = 'Operation' then
  begin
    AStyle := cxstylNewOperation;
  end
  else if AItem.EditValue = 'Admission' then
  begin
    AStyle := cxstylNewAdmission;
  end
  else if AItem.EditValue = 'Transfer' then
  begin
    AStyle := cxstylNewAdmission;
  end
  else
  begin
    AStyle := cxstylNewNormal;
  end;
但是当我使用这段代码时,项目的所有样式都被更改为一种样式,即使
AItem.EditValue
彼此不同

此外,当我在这些项目上单击或鼠标时,样式会自动更改


如何修复此代码?

您需要测试数据记录参数。我认为AItem代表de项(列),而不是您正在测试的记录的值

这样做你就会没事了:

//You can test if the Value is not null before the conditions, or use
//VarToStr (on unit Variants)
AStyle := cxstylNewNormal;
if ARecord.Values[AItem.Index] = 'Discharge' then
    AStyle := cxstylNewDischarge
else
if ARecord.Values[AItem.Index] = 'Operation' then
    AStyle := cxstylNewOperation
else 
if ARecord.Values[AItem.Index] = 'Admission' then
    AStyle := cxstylNewAdmission
else 
if ARecord.Values[AItem.Index] = 'Transfer' then
    AStyle := cxstylNewAdmission;
end;

你把代码放在哪里?我刚刚使用
cxGrid
onGetItemStyle
事件处理程序进行了一个快速测试,以基于
editValue
控制样式分配,它正常工作。我用
devExpress 13.2.3
在Delphi XE5上测试了这一点。