如何改变dbgrid中一行的颜色?(100分)

  • 主题发起人 主题发起人 xuyingfeng
  • 开始时间 开始时间
将dgRowSelect设为True。
 
接下来呢?
 
在DBGRID的onDrawColummCell事件中写代码吧。
if ... then
DBGrid.Canvas.Font.Color := clBlue;
DBGrid.DefaultDrawColumnCell(Rect, DataCol, Column, State);


 
建议用ehlib
 
比较麻烦,:-《
 
这样的效果试试,具体怎样才能适合你则要发挥你的才智了:
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
inherited;
With DbGrid1 do
begin
if ((State = [gdSelected]) or (State = [gdSelected,gdFocused])) then
begin
Canvas.Font.Color := clYellow;
Canvas.Brush.Color := clNavy;
end
else
begin
if Table2.RecNo mod 2 <> 0 then Canvas.Brush.Color := clWhite
else Canvas.Brush.Color := $00EAEAEA;
end;
DefaultDrawColumnCell(Rect,DataCol,Column,State);
end;
end;
 
这是我的原吗:
//when checkbox checked change the row color ManualAudit grid
用dbgrid 的onGridDrawDataCell事件:
procedure TAuditPanel.ManumalAudit_AccountGridDrawDataCell(Sender: TObject; const Rect: TRect;
Field: TField; State: TGridDrawState);
begin
with Sender as TwwDbGrid do
begin
if ((DataSource.Dataset as TAdoTable).FieldByName('point').AsInteger=1)or
((DataSource.Dataset as TAdoTable).FieldByName('selectedSigned').AsInteger=1)then
begin
Canvas.Font.Color := clRed;
DefaultDrawDataCell(Rect, Field, State);
end;
end;
end;
 
双击dbgrid 然后再增加行,设置fieldname和color属性就行了呀
 
RedBeret, cnaoszh 和在一起就是答案了。
 
多人接受答案了。
 
后退
顶部