1、在程序Form里面加一个d1:TClientdataset; 打开字段编辑器,添加一个string字段 sss; 2、在formOncreate事件里面添加: d1.CreateDataSet; d1.Open; 3、在Dbgrid所对应adoDataset1的DatasetAfterScroll事件里面假如代码 if not d1.Active then exit; if not d1.Locate('sss',inttostr(adodataset1.RecNo),[]) then Begin d1.Append; d1.FieldByName('sss').asstring:= inttostr(adodataset1.RecNo); d1.Post; End; 4、在dbgrid1的DrawColumnCell事件里面添加 if d1.Locate('sss',inttostr(adodataset1.RecNo),[])then Dbgrid1.Canvas.Brush.Color:=clMoneygreen; Dbgrid1.DefaultDrawColumnCell(rect,datacol,column,state);ok. //------------ 其实就是用一个ClientDataset记录下adodataset1的记录编号 然后判断一下对dbgrid进行改变背景色。不过因为用了ClientDataset所以需要midas.dll
//多行同时选择 DBGrid1.Options:=[dgRowSelect,dgMultiSelect];//改变高亮背景色 procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); begin if gdSelected in State then Canvas.Font.Color :=clBackground; DefaultDrawColumnCell(Rect,DataCol,Column,State); end;
Draws the text in a column cell.Delphi syntax:procedure DefaultDrawColumnCell(const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);C++ syntax:void __fastcall DefaultDrawColumnCell(const Types::TRect &Rect, int DataCol, TColumn* Column, Grids::TGridDrawState State);DescriptionCall DefaultDrawColumnCell from an OnDrawColumnCell event handler to lookup up the text representation of a field and write it to the cell. DefaultDrawColumnCell does exactly what the grid does when the DefaultDrawing property is true, except it never draws a focus rectangle on selected cells.The Rect parameter is the position of the cell on the canvas. The DataCol parameter is the index of the column in the Columns array. The Column parameter is the TColumn object that describes the display attributes and field binding for the cell. The State parameter indicates whether the cell has input focus, whether the cell is selected, and whether the cell is a fixed (non-data) cell such as a column header.
1、在程序Form里面加一个d1:TClientdataset; 打开字段编辑器,添加一个string字段 sss; 2、在formOncreate事件里面添加: d1.CreateDataSet; d1.Open; 3、在Dbgrid所对应adoDataset1的DatasetAfterScroll事件里面假如代码 if not d1.Active then exit; if not d1.Locate('sss',inttostr(adodataset1.RecNo),[]) then Begin d1.Append; d1.FieldByName('sss').asstring:= inttostr(adodataset1.RecNo); d1.Post; End; 4、在dbgrid1的DrawColumnCell事件里面添加 if d1.Locate('sss',inttostr(adodataset1.RecNo),[])then Dbgrid1.Canvas.Brush.Color:=clMoneygreen; Dbgrid1.DefaultDrawColumnCell(rect,datacol,column,state);ok. //------------ 其实就是用一个ClientDataset记录下adodataset1的记录编号 然后判断一下对dbgrid进行改变背景色。不过因为用了ClientDataset所以需要midas.dll
默认的是深蓝色,假如我想修改它的底色,该怎么做呢. 先谢谢了,关注此贴.
2、在formOncreate事件里面添加:
d1.CreateDataSet;
d1.Open;
3、在Dbgrid所对应adoDataset1的DatasetAfterScroll事件里面假如代码
if not d1.Active then exit;
if not d1.Locate('sss',inttostr(adodataset1.RecNo),[]) then
Begin
d1.Append;
d1.FieldByName('sss').asstring:= inttostr(adodataset1.RecNo);
d1.Post;
End;
4、在dbgrid1的DrawColumnCell事件里面添加
if d1.Locate('sss',inttostr(adodataset1.RecNo),[])then
Dbgrid1.Canvas.Brush.Color:=clMoneygreen; Dbgrid1.DefaultDrawColumnCell(rect,datacol,column,state);ok.
//------------
其实就是用一个ClientDataset记录下adodataset1的记录编号 然后判断一下对dbgrid进行改变背景色。不过因为用了ClientDataset所以需要midas.dll
DBGrid1.Options:=[dgRowSelect,dgMultiSelect];//改变高亮背景色
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if gdSelected in State then
Canvas.Font.Color :=clBackground;
DefaultDrawColumnCell(Rect,DataCol,Column,State);
end;
DefaultDrawColumnCell(Rect,DataCol,Column,State);是什么意思,为什么编译不过去? 我是希望只要单击了一条记录,它就保持高亮显示不变,即使不按下Control键,逐条点击之后它们也都能保持高亮显示的状态不变。
2、在formOncreate事件里面添加:
d1.CreateDataSet;
d1.Open;
3、在Dbgrid所对应adoDataset1的DatasetAfterScroll事件里面假如代码
if not d1.Active then exit;
if not d1.Locate('sss',inttostr(adodataset1.RecNo),[]) then
Begin
d1.Append;
d1.FieldByName('sss').asstring:= inttostr(adodataset1.RecNo);
d1.Post;
End;
4、在dbgrid1的DrawColumnCell事件里面添加
if d1.Locate('sss',inttostr(adodataset1.RecNo),[])then
Dbgrid1.Canvas.Brush.Color:=clMoneygreen; Dbgrid1.DefaultDrawColumnCell(rect,datacol,column,state);ok.
//------------
其实就是用一个ClientDataset记录下adodataset1的记录编号 然后判断一下对dbgrid进行改变背景色。不过因为用了ClientDataset所以需要midas.dll