델파이

TStringGrid 셀 내용 클립보드 복사

미스터몽키 2019. 8. 22. 04:04

스트링그리드의 셀 내용을 클립보드에 복사하는 다양한 방법


uses  Clipbrd;

...


(방법1) 외부 버튼

procedure TForm1.SpeedButton1Click(Sender: TObject);

var

  S: string;

  GRect: TGridRect;

  C, R: Integer;

begin

  GRect := sGrid.Selection;

  S  := '';

  for R := GRect.Top to GRect.Bottom do

  begin

    for C := GRect.Left to GRect.Right do

    begin

      if C = GRect.Right then  S := S + (sGrid.Cells[C, R])

      else

        S := S + sGrid.Cells[C, R] + #9;

    end;

    S := S + #13#10;

  end;

  ClipBoard.AsText := S;

end;


(방법2)   OnKeyPress     Ctrl+C

procedure TForm1.sGridKeyPress(Sender: TObject; var Key: Char);

begin

  case Key of

    #3: begin // Ctrl-C

//      if not sGrid.EditorMode then

        Clipboard.AsText := sGrid.Cells[sGrid.Col, sGrid.Row];

    end;

  end;


(방법3)  팝업메뉴

procedure TForm1.miCellCopyClick(Sender: TObject);

begin

  Clipboard.AsText := sGrid.Cells[sGrid.Col, sGrid.Row];

end;




(참고) OnKeyPress     복사 및 붙여넣기


  case Key of

    #3: begin // Ctrl-C

      if not sGrid.EditorMode then

        Clipboard.AsText := sGrid.Cells[sGrid.Col, sGrid.Row];

    end;

    #22: begin // Ctrl-V

      if not sGrid.EditorMode then

        sGrid.Cells[sGrid.Col, sGrid.Row] := Clipboard.AsText;

    end;

  end;