Home > Back-end >  I want to judge the comparison of three column value judgment conditions after the background color
I want to judge the comparison of three column value judgment conditions after the background color

Time:10-12

I want to judge the comparison of three column value judgment conditions after the background color of the change, the following, I don't know where there is a mistake? In addition, also note what will demonstrate success? I am a novice so, please detail point, thank you!
Procedure TForm17. DBGrid1DrawColumnCell (Sender: TObject; Const the Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
The begin
If ADOQuery1. FieldByName (' data ') AsString & lt; ADOQuery1. FieldByName (' minimum ') AsString then
DBGrid1. Canvas. Brush. Color:=clred;
DBGrid1. DefaultDrawColumnCell (the Rect, DataCol, the Column, the State);
If ADOQuery1. FieldByName (' data ') AsString & gt; ADOQuery1. FieldByName (' maximum). AsString then
DBGrid1. Canvas. Brush. Color:=clred;
DBGrid1. DefaultDrawColumnCell (the Rect, DataCol, the Column, the State);
end;

CodePudding user response:


When "field 2" less than "field 1" value, it shows red, when the "field 2" is more than "field 3", it shows yellow,
Three fields are ADOQuery1 query value,
Ask how your code, thank you detail more!

CodePudding user response:

 procedure TForm7. DBGrid1DrawColumnCell (Sender: TObject; Const the Rect: TRect; 
DataCol: Integer; Column: TColumn; State: TGridDrawState);
The begin
With DBGrid1. The DataSource. The DataSet do begin
If FieldByName (' field 2.) AsInteger & lt; FieldByName (' field 1.) AsInteger then
DBGrid1. Canvas. Brush. Color:=clred
Else if FieldByName (' field 2.) AsInteger & gt; FieldByName (' field 3.) AsInteger then
DBGrid1. Canvas. Brush. Color:=clYellow
The else
DBGrid1. Canvas. Brush. Color:=clWindow;
end;
DBGrid1. Canvas. FillRect (the Rect);
If (State=[gdSelected]) or (State=[gdSelected gdFocused]) then
DBGrid1. Canvas. The font color:=clBlue
The else
DBGrid1. Canvas. The font color:=clblack;
DBGrid1. DefaultDrawColumnCell (the Rect, DataCol, the Column, the State);
end;

CodePudding user response:



When "field 2" less than "field 1" value, it shows red, when the "field 2" is more than "field 3", it shows yellow,
"Field 1" "field 2" "field 3" from the three fields are ADOQuery1 calculated value, upstairs can change, use ADOQuery,
Ask how your code, thank you detail more!

CodePudding user response:

refer to the second floor gzzai response:
can change under?
[/code]


Could you change the?

CodePudding user response:

2 better no upstairs,

CodePudding user response:

Your code, a total of two "DBGrid1. DefaultDrawColumnCell (the Rect, DataCol, the Column, the State);" , remove the previous one, only in the last refresh with this sentence,

CodePudding user response:

Ever give a correct answer, continue to the top,

CodePudding user response:

My is Windows 7, I do not know can't change color and is there a link between the system,

CodePudding user response:

I think logic to be clear first, if there is a group of 5 4 3 number
So this time shows what color?



CodePudding user response:

references 9 f smile_ps response:
I think logic to find out, if there is a set of 5 4 3 number
So this time shows what color?

Logic is very clear to me ah, be "field 2" in between "field 1" and "field 3" of time, not coloring, "field 2" less than "field 1" the bank shows red, "field 2" more than "field 1" value, the bank shows yellow,
Expression should be clear, isn't it?

CodePudding user response:

Continue to the top, until there is the answer,

CodePudding user response:

refer to 6th floor ZBDZJX response:
your code, a total of two "DBGrid1. DefaultDrawColumnCell (the Rect, DataCol, the Column, the State);" , remove the previous one, only need to refresh with it finally,


The above no?? And change the AsString AsInteger, because use AsString result is not necessarily the right,

CodePudding user response:

Strange, no, in addition, I in the BBS search a few examples, are not able to show color changes,
Mine is 64 operating system, Windows 7 xe2 software, are related to this,
Procedure TForm17. DBGrid2DrawColumnCell (Sender: TObject; Const the Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
The begin
If ADOQuery2. FieldByName (' warehouse number.) AsInteger=1 then
The begin
Dbgrid2. Canvas. Brush. Color:=clYellow;
DBGrid2. DefaultDrawColumnCell (the Rect, DataCol, the Column, the State);
end;
end;
The color have no reaction,
Procedure TForm17. DBGrid4DrawColumnCell (Sender: TObject; Const the Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
The begin
With DBGrid4. The DataSource. The DataSet do begin
If FieldByName (' inventory '.) AsInteger & lt; FieldByName (' safety stock '.) AsInteger then
DBGrid4. Canvas. Brush. Color:=clred
Else if FieldByName (' inventory '.) AsInteger & gt; FieldByName (' highest inventory). AsInteger then
DBGrid4. Canvas. Brush. Color:=clYellow
The else
DBGrid4. Canvas. Brush. Color:=clWindow;
end;
DBGrid4. Canvas. FillRect (the Rect);
If (State=[gdSelected]) or (State=[gdSelected gdFocused]) then
DBGrid4. Canvas. The font color:=clBlue
The else
DBGrid4. Canvas. The font color:=clblack;
DBGrid4. DefaultDrawColumnCell (the Rect, DataCol, the Column, the State);
end;
Color also have no reaction,
What reason? Isn't there a able to find the cause of the problem?

CodePudding user response:

reference 13 floor wallyhost reply:
strange, no, on the other hand, I was in the BBS search a few examples, are not able to show color changes,
Mine is 64 operating system, Windows 7 xe2 software, are related to this,
Procedure TForm17. DBGrid2DrawColumnCell (Sender: TObject; Const the Rect: TRect;
DataCol: Integer; nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related