大家帮我解决一个燃眉之急的问好吗? (45分)

  • 主题发起人 主题发起人 小弟(陈生)
  • 开始时间 开始时间

小弟(陈生)

Unregistered / Unconfirmed
GUEST, unregistred user!
是这样的我想把一个数库里面的每行的数据的颜色改变,但我把颜色改变之后还想做到当我点击
其中任何一条数据时那行的数据的背景色就会改变。可是我用的是dxDBGrid这个控件啊,这个控件大家能行吗?
我颜色改变的代码是:
procedure TForm1.dxDBGrid1CustomDrawCell(Sender: TObject; ACanvas: TCanvas;
ARect: TRect; ANode: TdxTreeListNode; AColumn: TdxTreeListColumn;
ASelected, AFocused, ANewItemRow: Boolean; var AText: String;
var AColor: TColor; AFont: TFont; var AAlignment: TAlignment;
var ADone: Boolean);
begin
if (ANode.Index mod 2)=0 then AColor:=$00F4F2EC
else AColor:= $00DCEEF3;
end;
请大家帮我改下好吗?
多谢!
 
procedure TfrmQuery.DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if gdSelected in State then
Exit;
if (TDBGrid(Sender).DataSource = nil) or (TDBGrid(Sender).DataSource.DataSet = nil) then
Exit;

if TDBGrid(Sender).DataSource.DataSet.State in [dsEdit, dsInsert] then
begin
TDBGrid(Sender).Color := $00B999B0;
end
else
begin
TDBGrid(Sender).Color := clWindow;

if TDBGrid(Sender).DataSource.DataSet.RecNo mod 2 = 0 then
TDBGrid(Sender).Canvas.Brush.Color := clInfoBk
else
TDBGrid(Sender).Canvas.Brush.Color := RGB(191, 255, 223);

TDBGrid(Sender).DefaultDrawColumnCell(Rect, DataCol, Column, State);

TDBGrid(Sender).Canvas.Pen.Color := $00C08000;
TDBGrid(Sender).Canvas.MoveTo(Rect.Left, Rect.Bottom);
TDBGrid(Sender).Canvas.LineTo(Rect.Right, Rect.Bottom);
TDBGrid(Sender).Canvas.LineTo(Rect.Right, Rect.Top);
end;
end;
 
dxDBGrid1.Options := dxDBGrid1.Options + [dgrowselect];
 
可是我用的是dxDBGrid这个控件啊这个控件你能行吗?
 
看Demo中的:CustomDraw Demo...
 
后退
顶部