cxgrid靜態表中的資料與資料庫中資料對比,不同的話使單元格變色,求大佬解答,分不多,見諒
uj5u.com熱心網友回復:
有人嗎,有人嘛,嘀嘀嘀uj5u.com熱心網友回復:
procedure TForm_TRW0.DBGridListDrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumnEh;
State: TGridDrawState);
var
sValue:string;
begin
if (Column.FieldName='bState') then //你要變色的列
begin
sValue=https://bbs.csdn.net/topics/GetValueFromDB; //從資料庫找值
if Column.Field.asstring<>sValue //表格的資料和資料庫里不同
begin
DBGridList.Canvas.Font.Color:=clRed; //這個單元格的顏色變紅
end;
end;
DBGridList.DefaultDrawColumnCell(Rect, DataCol, Column, State); //重要,這句一定要加
end;
uj5u.com熱心網友回復:
貼一段StringGrid換色代碼procedure TFrm_LmsBase.StrGrid_DataDrawCell(Sender: TObject; ACol,
ARow: Integer; Rect: TRect; State: TGridDrawState);
begin
if (ARow=0)or(ACol=0) then
begin
with TStringGrid(Sender) do
begin
Canvas.Brush.Color:= clBtnFace;
Canvas.FillRect(Rect);
Canvas.font.color:=ClBlack;
Canvas.TextOut(rect.left, rect.top+FTextTop, cells[acol, arow]);
end;
exit;
end;
//隔行換色
if (ARow mod 2)=0 then
begin
if not (gdSelected in State) then
begin
with TStringGrid(Sender) do
begin
Canvas.Brush.Color:= $00F9F9F9;
Canvas.FillRect(Rect);
Canvas.font.color:=ClBlack;
Canvas.TextOut(rect.left, rect.top+FTextTop, cells[acol, arow]);
end;
end;
end
else
begin
if not (gdSelected in State) then
begin
with TStringGrid(Sender) do
begin
Canvas.Brush.Color:= clWhite;
Canvas.FillRect(Rect);
Canvas.font.color:= ClBlack;
Canvas.TextOut(rect.left, rect.top+FTextTop, cells[acol, arow]);
end;
end;
end;
//選中換色
With TStringGrid(Sender) do
begin
If (ARow= TStringGrid(Sender).Row) and not (acol = 0) then
begin
Canvas.Brush.Color:= $00CCCC99;
Canvas.FillRect(Rect);
Canvas.font.color:= ClBlack;
Canvas.TextOut(rect.left, rect.top+FTextTop, cells[acol, arow]);
end;
end;
end;
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/32612.html
標籤:數據庫相關
上一篇:旋光物質吸光度測量
下一篇:一次滑稽的解決程序
