어떤 분의 소스를 가지고 스트링그리드에 체크박스를 넣었습니다.
type
TstCellObj = packed record
case Integer of
0 : ( Num : Integer);
1 : ( Sender : TObject);
end;
type
TCellObj = class
public
bChecked: boolean;
str: String;
end;
implementation
{$R *.dfm}
procedure DrawCheck(DC:HDC;BBRect:TRect;bCheck:Boolean);
begin
if bCheck then
DrawFrameControl(DC, BBRect, DFC_BUTTON, DFCS_BUTTONCHECK + DFCS_CHECKED)
else
DrawFrameControl(DC, BBRect, DFC_BUTTON, DFCS_BUTTONCHECK);
end;
procedure TPayment_Prt.bosu_gridDrawCell(Sender: TObject; ACol,
ARow: Integer; Rect: TRect; State: TGridDrawState);
var
pStr: string;
pLeft: integer;
arect: TRect;
CelObj: TstCellObj;
begin
//0번째 행에 제목 정렬
with (Sender as TStringGrid) do
begin
SetTextAlign(handle, ta_left);
pStr := Cells[ACol, ARow];
if (acol = 0) or (acol = 1) or (acol = 2) or (acol = 4) or (arow = 0) then//가운데 정렬
begin
pLeft := ((Rect.Right - Rect.Left - Canvas.TextWidth(pStr)) div 2) + Rect.Left;
Canvas.TextRect(Rect, pLeft, Rect.Top + 2, pStr);
end;
end;
with TStringGrid(Sender).Canvas do begin
if ARow > 0 then begin
if ACol = 0 then begin
// 3. CheckBox 그리기
with (Sender As TStringGrid) do begin
//화면을 지웁니다.
Canvas.FillRect(Rect);
// arect는 크기입니다. Box크기를 보고 조절하세요.
arect := Rect;
arect.Top := Rect.Top + 5;
arect.Bottom := Rect.Bottom - 5;
CelObj.Sender:=Objects[ACol,ARow];
DrawCheck(Canvas.Handle, arect, CelObj.Num = 1);
end;
end;
end;
end; // with end
end;
procedure TPayment_Prt.bosu_gridClick(Sender: TObject);
var
CelObj: TstCellObj;
pt: TPoint;
ACol,ARow: Integer;
begin
pt:=Mouse.CursorPos;
pt:=bosu_grid.ScreenToClient(pt);
bosu_grid.MouseToCell(pt.x,pt.y,ACol,ARow);
if (ARow>0) and (ACol=0) then
begin
CelObj.Sender:=bosu_grid.Objects[ACol,ARow];
if CelObj.Num=1 then CelObj.Num:=0
else CelObj.Num:=1;
bosu_grid.Objects[ACol,ARow]:=CelObj.Sender;
bosu_grid.Invalidate;
Exit;
end;
end;
출력버튼을 누르면 인쇄할려고 하는데 버튼안에 어떻게 코딩해야 하는지......
procedure TPayment_Prt.bosu_prtClick(Sender: TObject);
var i : integer;
begin
for i:=1 to bosu_grid.RowCount do
begin
출력;
end;
end;
출력버튼을 눌렀을때 1번째 행부터 마지막행까지 순차적으로 검색을 해서 체크박스가 True이면
출력할려고 하는데 IF문에 어떻게 코딩을 해야하는지 모르겠습니다.
if bosu_grid.cells[0,i).check = true then 또는
if bosu_grid.object[0,i].true가 맞는지 아님 어떻게 기술해야 하는지......
var
i : integer;
begin
for i:= 1 to bosu_grid.RowCount-1 do begin
if TstCellObj(bosu_grid.Objects[0, i]).Num = 1 then
showmessage(intToStr(i) + '출력');
end;
end;