Home > Back-end >  Delphi xe7 the tclientdataset, dbgrid display a column value is less than 30 red, the result is the?
Delphi xe7 the tclientdataset, dbgrid display a column value is less than 30 red, the result is the?

Time:05-05

Xe7 clientdatset (cdsrope) + dbgrid,
One CDS there were two calculated fields (duedate, balance) are fkinternalcalc types,
In CDS oncalc events in computing the two field value, want to according to the value of the balance in the dbgrid, if less than 30 red bold, or normal, according to
On the contrary, a long time, and the results and expected trouble master look at code where there is a problem, or a set?

The calculation of the CDS event process is as follows:
 procedure TfmQuRope. CdsQueryCalcFields (DataSet: TDataSet); 
The begin
//self. CdsQuery.
//if the dataset. State=dsinternalcalc then
The begin
The dataset. FieldByName (' duedate). AsDateTime:=the dataset. FieldByName (" begindate "). AsDateTime +
Self. CdsQuery. FieldByName (' life '). AsInteger;
The dataset. FieldByName (' the balance '). AsInteger:=trunc (dataset. FieldByName (" begindate "). AsDateTime
- today) + dataset. FieldByName (' life '). AsInteger;
end;
end;


Dbgrid drawcolumncell events is as follows:
 procedure TfmQuRope. DBGrid1DrawColumnCell (Sender: TObject; Const the Rect: TRect; 
DataCol: Integer; Column: TColumn; State: TGridDrawState);
The begin
If self. CdsQuery. RecNo mod 2=0 then
(Sender as TDBGrid). Canvas. Brush. Color:=clskyblue
The else
(Sender as TDBGrid). Canvas. Brush. Color:=clwindow;
If gdselected in State then
(Sender as TDBGrid). Canvas. Brush. Color:=clolive;
//if (sametext (Column FieldName, 'the balance')=true) and
//(self) DBGrid1) Columns [DataCol]. Items [1] <30) then
If (datacol=24) and
(Column. Field. AsInteger & lt; Fmmain. AdvanceDay) then
//is that judge whether the value of the current column is less than 30
The begin
//the Column, the Font Style:=Column. The Font. The Style + [fsbold];
The Column, the Font Color:=clred;
End
The else
The begin
The Column, the Font Color:=cldefault;
//the Column, the Font Style:=Column. The Font. The Style - [fsbold];
end;
(Sender as TDBGrid). DefaultDrawColumnCell (the Rect, DataCol, the Column, the State);


Also found that because of the dbgrid balance inside the title field width is 94 by default, all the fields are bold by default, the runtime, the mouse pull the width, bold, will not display if the design width adjustment after 95, when the column value is not bold,

  • Related