線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1754
推到 Plurk!
推到 Facebook!

TStringGrid 中的checkbox 如何判斷是否已經checked.

尚未結案
tidal
初階會員


發表:93
回覆:32
積分:25
註冊:2003-07-15

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-01-07 13:49:38 IP:202.82.xxx.xxx 未訂閱
這是引用一位大大其中的code,請問如何判斷圖中Cells[1,2] 中的checkbox 是否 checked?     程式碼如下:
 
unit Unit1;    interface    uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids, StdCtrls;    type
  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
    procedure gridcheckboxMouseDown(Sender: TObject; Button: TMouseButton;
              Shift: TShiftState; X, Y: Integer);
    procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    procedure StringGrid1TopLeftChanged(Sender: TObject);      private
    { Private declarations }
  public
    { Public declarations }
  end;    var
  Form1: TForm1;    implementation    {$R *.dfm}    procedure TForm1.FormCreate(Sender: TObject);
var
chk:TcheckBox;
i,j:integer;
begin
StringGrid1.RowCount:=30;
StringGrid1.ColCount:=10;
for i:= 1 to 9 do begin
  for j:=1 to 29 do begin
    StringGrid1.Cells[i,j]:='';
    chk:=Tcheckbox.Create(Stringgrid1);
    chk.name:=format('CellChk%d_%d',[i,j]);
    chk.Caption:='';
    chk.Checked:=false;
    chk.Visible:=false;
    chk.parent:=stringgrid1;
    chk.width:=chk.Height;
    chk.OnMouseDown:=gridcheckboxMouseDown;
    Stringgrid1.Objects[i,j]:=chk;
  end;
end;    end;    procedure TForm1.gridcheckboxMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);    begin
With Sender As TCheckbox Do
Checked := not Checked;    end;    procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
var
chk: TCheckbox;
grid: TStringgrid;
begin
grid := Sender As TStringgrid;
//if (aCol = 1) and (aRow >= grid.FixedRows)
if ((aRow >= grid.FixedRows) and (aRow <= grid.RowCount)) and ((ACol >= grid.FixedCols) and (ACol <= grid.ColCount))
then begin
chk:= TCheckbox(grid.Objects[ aCol, aRow ]);
If Assigned(chk) Then Begin
chk.SetBounds( (rect.left + rect.right - chk.width) div 2,
(rect.top + rect.bottom - chk.height) div 2,
chk.width, chk.height );
if not chk.visible then
chk.show; 
End;
end;    end;    type
tgridcracker = Class( tstringgrid );        procedure TForm1.StringGrid1TopLeftChanged(Sender: TObject);
begin
tgridcracker(Sender).InvalidateCol(1);
end;    end.    
shinjie
資深會員


發表:12
回覆:275
積分:287
註冊:2003-03-19

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-01-07 14:40:23 IP:203.73.xxx.xxx 未訂閱
圖中的Cell好像是1,1說 procedure TForm1.Button1Click(Sender: TObject); var chk: TCheckbox; begin //方法一 chk:= TCheckbox(StringGrid1.Objects[1,1]); showmessage(BoolTOStr(chk.checked)); //方法二 showmessage(BoolToStr((Form1.StringGrid1.FindComponent(format('CellChk%d_%d',[1,1])) as TCheckBox).Checked)); end;
------
我將在茫茫人海中尋訪我唯一之靈魂伴侶。
得之;我幸。不得;我命。
系統時間:2024-05-24 5:51:33
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!