不知怎么刷新!(100分)

T

typer

Unregistered / Unconfirmed
GUEST, unregistred user!
我写了下面的代码,用来在DBGrid下面加一行,但当Columns的长度由大于DBGrid的宽度拖到小于DBGrid的宽度时,后面仍留着一些匡格,不知怎么刷新!
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
var
Rct:Trect;
begin
if (Rect.right>DBGrid1.Width) then
rct.right:=DBGrid1.Left+DBGrid1.Width
else rct.right:=DBGrid1.Left+Rect.right;
Form1.Canvas.pen.color:=clred;
Form1.Canvas.RectangleDBGrid1.left+Rect.left,DBGrid1.top+DBGrid1.height, rct.right,DBGrid1.top+DBGrid1.Height+Rect.Bottom-Rect.top);
end;
 
和你的Grid相连的Table如果Active:=Fasle;是没用的,你
试试Acive:=True;
 
对不起,没看清楚你的问题:)
 
//THAT 's MY CODE.

procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
var Rct:Trect;
begin
if (Rect.right>DBGrid1.Width) then
rct.right:=DBGrid1.Left+DBGrid1.Width
else rct.right:=DBGrid1.Left+Rect.right;
Form1.Canvas.Brush.Color:=clWhite;
Form1.Canvas.pen.color:=clred;
Form1.Canvas.Rectangle(DBGrid1.left+Rect.left,
DBGrid1.top+DBGrid1.height,
rct.right,
DBGrid1.top+DBGrid1.Height+Rect.Bottom-Rect.top);
Form1.Canvas.Brush.Color:=Form1.Color;//set color to backgroud color
Form1.Canvas.pen.color:=Form1.Color;//set color to backgroud color
Form1.Canvas.Rectangle(Rct.Right, //clear right rect
DBGrid1.top+DBGrid1.height,
DBGrid1.Left+DBGrid1.Width,
DBGrid1.top+DBGrid1.Height+Rect.Bottom-Rect.top);
end;


Give me the POINT? :)
 
menxin Don't anxious!
Yesterday I have another question.
When the DataSet have a lot of Record ,the overhead
of the draw is big.
How to Judge when DBgrid drawing the last row?
 
你的问题我无法有完美的解决办法。因为只重画grid中的最后一条好象不好做。
不过加入一全局变量可大量减少重画次数。
recsave:integer;
在相关dataset的SCROLL中加入如下代码:

procedure TForm1.Table1AfterScroll(DataSet: TDataSet);
begin
recsave:=DataSet.RecNo;
end;

在dbgrid.drawcol中加入一行:

if DBGrid1.DataSource.DataSet.RecNo<>recsave then exit;即可

意思是只重画指定记录。这样虽然可减少2/3左右的重画,但我还是建议你尽量
减少重画时的代码,几种方法一齐使用吧。good lucky.


 
接受答案了.
 

Similar threads

I
回复
0
查看
700
import
I
I
回复
0
查看
528
import
I
I
回复
0
查看
570
import
I
I
回复
0
查看
665
import
I
I
回复
0
查看
560
import
I
顶部