delphi - coloring cxdbgrid field depending on its content

巧了我就是萌 提交于 2019-12-14 02:48:34

问题


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:


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


来源:https://stackoverflow.com/questions/20183431/delphi-coloring-cxdbgrid-field-depending-on-its-content

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!