DevExpress TcxGridDBLayoutViewItem OngetContentStyle不起作用

时间:2015-03-03 02:12:23

标签: delphi styles devexpress

我使用DevexpressDelphi 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彼此不同,所有项目样式也只会更改为一种样式。

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

如何修复此代码?

1 个答案:

答案 0 :(得分:0)

你需要测试de ARecord Param。我认为AItem代表de Item(列),而不是你正在测试的记录的值。

这样做,你应该没问题:

//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;