表中加字段isSel,如果双击后则为true with (Sender as TDBGridEh).Canvas do begin if ADOQuery1.fieldbyname('Xwlx').AsString='通用类询问笔录' then if ADOQuery1.fieldbyname('isSel').AsBoolean=true then begin Brush.Color :=clSkyBlue; FillRect(Rect); TextOut(Rect.Left, Rect.Top, Column.Field.DisplayText); end else begin Brush.Color :=clBtnFace; FillRect(Rect); TextOut(Rect.Left, Rect.Top, Column.Field.DisplayText); end; end;
with (Sender as TDBGridEh).Canvas do begin if ADOQuery5.FieldByName('IsSel').AsBoolean then begin Brush.Color:=clSkyBlue; FillRect(Rect); DBGridEh5.DefaultDrawColumnCell(Rect,DataCol,Column,[gdFixed,gdFocused,gdSelected]); end else begin Brush.Color:=clBtnFace; FillRect(Rect); DBGridEh5.DefaultDrawColumnCell(Rect,DataCol,Column,[gdFixed,gdFocused,gdSelected]); end; end;
那你还不如在GRIDE中加CHECKBOX 这样不更好看一些?
procedure TfrmTyxwbl.DBGridEh5DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumnEh; State: TGridDrawState); begin with (Sender as TDBGridEh).Canvas do begin if ADOQuery5.FieldByName('IsSel').AsBoolean then begin Brush.Color:=clSkyBlue; FillRect(Rect); DBGridEh5.DefaultDrawColumnCell(Rect,DataCol,Column, [gdFixed,gdFocused,gdSelected]); end else begin Brush.Color:=clBtnFace; FillRect(Rect); DBGridEh5.DefaultDrawColumnCell(Rect,DataCol,Column, [gdFixed,gdFocused,gdSelected]); end; end; end;
http://www.delphibbs.com/keylife/iblog_show.asp?xid=27763
然后
在 DBGrid.OnDrawColumnCell(...) 中:begin
if TableField.AsInteger < 0 then
DBGrid.Canvas.Font.Color := clRed
else
DBGrid.Canvas.Font.Color := clBlack;
DBGrid.DefaultDrawColumnCell(...);
end;
DBGrid1双击后把该条记录的内容写入Memo1中,同时该条记录的颜色想换一下以表明该条记录已选过
with (Sender as TDBGridEh).Canvas do
begin
if ADOQuery1.fieldbyname('Xwlx').AsString='通用类询问笔录' then
if ADOQuery1.fieldbyname('isSel').AsBoolean=true then
begin
Brush.Color :=clSkyBlue;
FillRect(Rect);
TextOut(Rect.Left, Rect.Top, Column.Field.DisplayText);
end
else
begin
Brush.Color :=clBtnFace;
FillRect(Rect);
TextOut(Rect.Left, Rect.Top, Column.Field.DisplayText);
end;
end;
begin
if ADOQuery5.FieldByName('IsSel').AsBoolean then
begin
Brush.Color:=clSkyBlue;
FillRect(Rect);
DBGridEh5.DefaultDrawColumnCell(Rect,DataCol,Column,[gdFixed,gdFocused,gdSelected]);
end
else
begin
Brush.Color:=clBtnFace;
FillRect(Rect);
DBGridEh5.DefaultDrawColumnCell(Rect,DataCol,Column,[gdFixed,gdFocused,gdSelected]);
end;
end;
DataCol: Integer; Column: TColumnEh; State: TGridDrawState);
begin
with (Sender as TDBGridEh).Canvas do
begin
if ADOQuery5.FieldByName('IsSel').AsBoolean then
begin
Brush.Color:=clSkyBlue;
FillRect(Rect);
DBGridEh5.DefaultDrawColumnCell(Rect,DataCol,Column,
[gdFixed,gdFocused,gdSelected]);
end
else
begin
Brush.Color:=clBtnFace;
FillRect(Rect);
DBGridEh5.DefaultDrawColumnCell(Rect,DataCol,Column,
[gdFixed,gdFocused,gdSelected]);
end;
end;
end;