Q&A

  • grid에 check box insert 작업후에 check box을 해제를 하고자 합니다.
안녕하세요

수고 많습니다.

string grid에 있는 체크박스가 해제가 되지 않습니다.
grid drawcell이벤트가 발생하면 grid 에 연관 된 이벤트가 발생하는것 같습니다. 그리고 grid 다른 이벤트가 실행하면 grid drawcell이벤트도 같이 작동하는것 같습니다. 해제를 해야하는데 해제가 되지 않습니다.
(drawcell event 발생 하지못하게 하는 방법은 없습니까? )
다른 해제 방법은 없습니까?

아래는 check box 작업과정 입니다.

procedure TFInvoice.kg1CellMUp(Sender: TObject; Shift: TShiftState; X, Y,
  ACol, ARow: Integer);
begin
with kg1 do
       begin
       for i1 := 1 to Rowcount - 1 do
           begin
           if kg1.Objects[10,i1] is TCheckBox Then
             begin
             TCheckBox(kg1.Objects[10, i1]).Free;//이부분에서 Access violation error가 발생합니다.
              end;
            end;

       checkboxshow;
       for i1:=1 to kg1.RowCount - 1 do
           begin
           if ((kg1.SCells[0, i1] <> '') and (kg1.NCells[11,i1] <> 0)) then
             begin
             with TCheckBox(kg1.Objects[10,i1]) do
                    begin
                    Checked:= not Checked;
                    end;
              end;
           end;
       end;
end;

procedure TFInvoice.kg1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
begin
if gfix1 = 0 then  
   begin
   if ((ACol = 10) and (kg1.Objects[ACol,ARow] is TCheckBox)) then
      begin
      With TCheckBox(kg1.Objects[ACol,ARow]) do
           begin
           top := Rect.Top + 1;
           Left := Rect.Left + 30;
           Visible := True;
           end;
      end;
   end;
end;

procedure TFInvoice.checkboxshow;
var
Sender: TObject;
begin
with kg1 do
     begin
     for i1 := 1 to Rowcount - 1 do
         begin
         if (SCells[0, i1] <> '') then
            begin
            kg1.Objects[10, i1]:=TCheckBox.Create(kg1);
            with TCheckBox(kg1.Objects[10, i1]) do
                 begin
                 Parent:=kg1;
                 OnKeyUp   :=CheckBoxKeyUp;
                 OnMouseUp :=CheckBoxMouseUp;
                 BoundsRect:=kg1.CellRect(10,i1);
                 Width     :=13;
                 Height    :=13;
                 top       :=kg1.CellRect(10,i1).Top;
                 Left      :=30;
                 tag       :=i1;
                 Checked   :=False;
                 Visible   :=False;
                 end;
            end;
         end;
     end;
end;

procedure TFInvoice.CheckBoxMouseUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var
  ic2 : Integer;
begin
   with TCheckBox(Sender) do
        begin
        Checked := not Checked;
        if Checked then
           begin
           with kg1 do
                begin

                end;
           end
        else
           begin
           with kg1 do
                NCells[11, TCheckBox(Sender).Tag]:=0;
           end;
        end;
Total_Sum_GridCall(1);        
end;

procedure TFInvoice.CheckBoxKeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var
  ic2 : Integer;
begin
if Key = VK_SPACE then
   with TCheckBox(Sender) do
        begin
        Checked := not Checked;
        if Checked then
           begin
           with kg1 do
                begin

                end;
           end
        else
           begin
           with kg1 do
                NCells[11, TCheckBox(Sender).Tag]:=0;
           end;
        end;

end;
0  COMMENTS