问题
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