请问各位,如何编写使StringGrid中的一列具有Check功能,和CheckBox效果一样(100分)

  • 主题发起人 主题发起人 季晓峰
  • 开始时间 开始时间

1.如果你实现接口的类是这样构造的.
TFaintCom = class(TInterfacedObject, IFaintCom)
那就判: RefCount
2.TRY ...EXCEPT(别生气, com)
 
SORRY, 写错地方了回头再道歉.
 
你要自己写控件了.
可参考DXDBGRID的源码
 
用TopGrid,很好用的。
 
To balaschen:TopGrid再那里有下
To delphifaq: 自己如何写呢?
请指点一下
 
写 DrawCell 事件吧,手工画一个 checkBox 在对应的 Cell 里
 
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Grids;

type
TForm1 = class(TForm)
grid: TStringGrid;
procedure FormCreate(Sender: TObject);
procedure gridDrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
procedure gridClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
fcheck,fnocheck:tbitmap;
implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
var
i:SmallInt;
bmp:TBitmap;
begin
FCheck:= TBitmap.Create;
FNoCheck:= TBitmap.Create;
bmp:= TBitmap.create;
try
bmp.handle := LoadBitmap( 0, PChar(OBM_CHECKBOXES ));
With FNoCheck Do Begin
width := bmp.width div 4;
height := bmp.height div 3;
canvas.copyrect( canvas.cliprect, bmp.canvas, canvas.cliprect );
End;
With FCheck Do Begin
width := bmp.width div 4;
height := bmp.height div 3;
canvas.copyrect(
canvas.cliprect,
bmp.canvas,
rect( width, 0, 2*width, height ));
End;
finally
bmp.free
end;
end;
procedure TForm1.gridDrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
if not (gdFixed in State) then
with TStringGrid(Sender).Canvas do
begin
brush.Color:=clWindow;
FillRect(Rect);
if Grid.Cells[ACol,ARow]='yes' then
Draw( (rect.right + rect.left - FCheck.width) div 2,
(rect.bottom + rect.top - FCheck.height) div 2,
FCheck )
else
Draw( (rect.right + rect.left - FCheck.width) div 2,
(rect.bottom + rect.top - FCheck.height) div 2,
FNoCheck );
end;
end;

procedure TForm1.gridClick(Sender: TObject);
begin
if grid.Cells[grid.col,grid.row]='yes' then
grid.Cells[grid.col,grid.row]:='no'
else
grid.Cells[grid.col,grid.row]:='yes';
end;

end.
 
忘了在form.destroy中free fcheck,fnocheck. :)
 
谢谢各位
 
后退
顶部