delphi - coloring cxdbgrid field depending on its

2019-07-23 22:36发布

I am not exactly sure how to put this. I am coloring cxDB grid field based on the value:

procedure TForm1.cxGrid1DBTableView1StylesGetContentStyle(
  Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord;
  AItem: TcxCustomGridTableItem; var AStyle: TcxStyle);
  var  AColumn: TcxCustomGridTableItem;
begin
AColumn := (Sender as TcxGridDBTableView).GetColumnByFieldName('SIFRA');
 if VarToStr(ARecord.Values[AColumn.Index]) =  '007 01' then
      AStyle := cxstyle1; 
end;

I would like to change the code so that all the fields that have 007 in the column get coloured.

1条回答
家丑人穷心不美
2楼-- · 2019-07-23 23:13

According to comments, you were looking for a way how to write a statement to determine if a certain text starts with a specified string. For this you can use e.g. the StartsText function (System.StrUtils). The following statement will evaluate to True if the current cell text starts with 007:

if StartsText('007', VarToStr(ARecord.Values[AColumn.Index])) then
查看更多
登录 后发表回答