在DBGRID中如何使当前行显示指定颜色? (50分)

  • 主题发起人 主题发起人 609394
  • 开始时间 开始时间
6

609394

Unregistered / Unconfirmed
GUEST, unregistred user!
我想问的是只使当前记录变色,也就是光标在哪行就哪行整行变色,它本身是一个字段
高亮显示,我要的是整一行都高亮反白显示,有请高手指教!
 
把DBGRID强制转换:
STRINGGRID(DBGRID)
后面跟上你要的颜色。
 
Dbgird->Option属性->RowSelected设为true;
 
http://211.101.4.25/delphibbs/dispq.asp?lid=1124866
 
我还想输入,怎么办?
 
点选当前行时,对此行进行重画,使用ONDRAWDARACELL事件,在此事件中,为其着色。OK
 
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
with DBGrid1 do
begin
if gdSelected in State then
begin
Canvas.Brush.Color := $00C08080;
Canvas.Font.Color := clWhite;
end;
DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;
end;

procedure TForm1.DBGrid1DblClick(Sender: TObject);
begin
if dgEditing in DBGrid1.Options then
begin
if not (dgRowSelect in DBGrid1.Options) then
DBGrid1.Options := DBGrid1.Options + [dgRowSelect] - [dgEditing] ;
end
else
begin
if dgRowSelect in DBGrid1.Options then
begin
DBGrid1.Options := DBGrid1.Options - [dgRowSelect] + [dgEditing] + [dgAlwaysShowEditor];
DBGrid1.Options := DBGrid1.Options - [dgRowSelect] + [dgEditing] - [dgAlwaysShowEditor]
end
end
end;
 
Dbgird->Option属性->RowSelected设为true好像只是整行高亮显示吧,
 
procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
Field: TField; State: TGridDrawState);
begin
if gdselected in state then
begin
dbgrid1.Canvas.Brush.Color:=clred; //选中的单元格的颜色
dbgrid1.Canvas.FillRect(rect);
dbgrid1.Canvas.Pen.Color:=clwhite; //选中的单元格的字体颜色
if VarType(Field.Value)=varNull then
dbgrid1.Canvas.TextOut(rect.left,rect.top,'')
else
dbgrid1.Canvas.TextOut(rect.left,rect.top,Field.Value);
end;
end;
 
試試這個﹕
procedure Tinfo.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if query1.FieldByName(’all’).asstring>40’ then
begin
dbgrid1.Canvas.Font.Color:=clred;
dbgrid1.Canvas.Brush.color:=clyellow;
end
else
begin
dbgrid1.Canvas.Font.Color:=clblue;
dbgrid1.Canvas.Brush.color:=clyellow;
end;

dbgrid1.DefaultDrawColumnCell(rect,datacol,column,state);
end;
 
多人接受答案了。
 

Similar threads

D
回复
0
查看
909
DelphiTeacher的专栏
D
D
回复
0
查看
704
DelphiTeacher的专栏
D
D
回复
0
查看
666
DelphiTeacher的专栏
D
后退
顶部