还是回答一下吧。procedure TForm1.Button1Click(Sender: TObject); begin with StringGrid1 do begin ShowMessage('从第 ' + IntToStr(Selection.Top) + ' 到第 ' + IntToStr(Selection.Bottom) + ' 行'); end; end;
设置stringgrid的一列来标示是否选中,下次就读这个值判断
var fcheck,fnocheck:tbitmap; implementationprocedure 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;
begin
with StringGrid1 do
begin
ShowMessage('从第 ' + IntToStr(Selection.Top)
+ ' 到第 ' + IntToStr(Selection.Bottom) + ' 行');
end;
end;
var
fcheck,fnocheck:tbitmap;
implementationprocedure 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;
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;