關於在StringGrid中插入CheckBox的問題..!在線等..! ( 积分: 20 )

J

Jj1985

Unregistered / Unconfirmed
GUEST, unregistred user!
我從數據庫裡取出數據在StringGrid中顯示..
但數據有長有短..所以行高不確定.! 所以我插入CheckBox的方法寫在了一個Trimer裡.
while not eof do
begin
CheckBoxs1:= TbsSkinCheckRadioBox.Create(bsSkinStringGrid1);
with CheckBoxs1 do
begin
Parent:=bsSkinStringGrid1;
Top:=RowHeight+RowHeights div 2;
Left:=100;
Width:=20;
Height:=20;
tag:=FieldByName('criterion_id').AsInteger;
end;
RowHeight:=RowHeight+bsSkinStringGrid1.RowHeights+1;
inc(I);
next;
end;
現在的問題是前面一部分的checkbox位置是對的.!而後面的就全部亂了.!
用showmessage(inttostr(RowHeight+RowHeights div 2)) 位置是對的!!
 
procedure TForm1.StringGrid1DrawCell(Sender: TObject;
ACol, ARow: Integer;
Rect: TRect;
State: TGridDrawState);
var
Pnt: TPoint;
i : Integer;
CBox : TCheckBox;
begin
for i := 0 to StringGrid1.ColCount-1 do
begin
if ARow = 0 then
begin
CBox := TCheckBox.Create(Self);
CBox.Parent := Self;
CBox.Checked := True;
CBox.Tag := 1;
CBox.Hint := inttostr(1);
with StringGrid1 do
begin
with Rect do
begin
Pnt := CBox.Parent.ScreenToClient((StringGrid1.ClientToScreen(Point(Left, Top))));
CBox.SetBounds(Pnt.X+1, Pnt.Y, 12, Bottom - Top);
end;
end;
end;
end;
end;

这个只是在StringGrid中添加CheckBox的代码。你试试
 
建议使用TMS Pack中的AdvStringGrid控件,很方便,能做出漂亮的界面来。
 
首先顶下楼主:尽量利用delphi自带的vcl,少用三方控件:缺少后期技术支持,程序的可移植性差。
问题应该出在座标问题,屏幕座标与设备座标;
subosoft正解
 
顶部