반응형

선택한 셀 내용을 엑셀 시트에 복사하기 (CTRL+C)
셀 색상을 바꿔놓았다면 셀 선택 시 텍스트 및 바탕이 하얗게 표시 되버리는 문제가 생긴다
해결법은 아래와 같이 gdSelected = false 일경우만 색이 바뀌게 해놓으면 정상적으로 표시 된다
procedure TAForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
begin

    if (ARow = 0) or (ACol=0) or (ACol=0) or (ACol=1) then
    begin
      if (State <> [gdSelected]) then //선택한 셀이 하얗게 되는것을 방지
      begin
        Canvas.Brush.Color := clInactiveCaptionText;   // 배경색을 바꿀때 사용
        canvas.TextRect(Rect, Rect.Left, Rect.Top, cells[ACol, ARow]);
      end;

    end;

end;

procedure TAForm1.StringGrid1KeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var
  CopyString : String;
  item_Index,Column_Index : Integer;
  i,j : Integer;
  sRec : TGridRect;
begin
  if (Shift = [ssCtrl]) and (Key = 67)then
  begin
    CopyString := '';
    sRec := TStringGrid(Sender).Selection;
    //클립보드 복사(Ctrl+C)


    For i := sRec.Top to sRec.Bottom do
    begin

      for j:= sRec.Left to sRec.Right Do
      begin
        CopyString := CopyString + TStringGrid(Sender).Cells[j,i] +#9;
      end;
      CopyString := CopyString + #13#10;
    end;

    Clipboard.SetTextBuf(PChar(CopyString));

  end;

end;

반응형
반응형