CodePudding user response:
Someone, anyone, di di diCodePudding user response:
Procedure TForm_TRW0. DBGridListDrawColumnCell (Sender: TObject;
Const the Rect: TRect; DataCol: Integer; Column: TColumnEh;
State: TGridDrawState);
Var
SValue: string;
The begin
If (Column. FieldName='bState) then//do you want to change color of the Column of
The begin
sValue=https://bbs.csdn.net/topics/GetValueFromDB;//from the database to find value
If the Column. Field. Asstring<> SValue//form different data and database
The begin
DBGridList. Canvas. The Font Color:=clRed;//the cell's color red
end;
end;
DBGridList. DefaultDrawColumnCell (the Rect, DataCol, the Column, the State);//important, it must add
end;
CodePudding user response:
Stick a StringGrid change color codeProcedure TFrm_LmsBase. StrGrid_DataDrawCell (Sender: TObject; ACol,
ARow: Integer; The Rect: TRect; State: TGridDrawState);
The begin
If (ARow=0) or (ACol=0) then
The begin
With TStringGrid (Sender) do
The begin
Canvas. Brush. Color:=clBtnFace;
Canvas. FillRect (the Rect);
Canvas. The font. Color:=ClBlack;
Canvas. TextOut (the rect. Left, the rect. Top + FTextTop, cells [acol, arow]);
end;
exit;
end;
//interlaced color change
If (ARow mod 2)=0 then
The begin
If not (gdSelected in State) then
The begin
With TStringGrid (Sender) do
The begin
Canvas. Brush. Color:=$00 f9f9f9;
Canvas. FillRect (the Rect);
Canvas. The font. Color:=ClBlack;
Canvas. TextOut (the rect. Left, the rect. Top + FTextTop, cells [acol, arow]);
end;
end;
End
The else
The begin
If not (gdSelected in State) then
The begin
With TStringGrid (Sender) do
The begin
Canvas. Brush. Color:=clWhite;
Canvas. FillRect (the Rect);
Canvas. The font. Color:=ClBlack;
Canvas. TextOut (the rect. Left, the rect. Top + FTextTop, cells [acol, arow]);
end;
end;
end;
//selected color change
With TStringGrid (Sender) do
The begin
If (ARow=TStringGrid (Sender). Row) and not (acol=0) then
The begin
Canvas. Brush. Color:=$00 cccc99;
Canvas. FillRect (the Rect);
Canvas. The font. Color:=ClBlack;
Canvas. TextOut (the rect. Left, the rect. Top + FTextTop, cells [acol, arow]);
end;
end;
end;