TStringGrid多选的复制与拷贝

翻译|其它|编辑:郝浩|2006-06-20 12:20:00.000|阅读 1281 次

概述:

# 界面/图表报表/文档/IDE等千款热门软控件火热销售中 >>


程序代码如下所示:

uses Clipbrd;
function StringGridSelectText(mStringGrid: TStringGrid): string;
var
I, J: Integer;
S: string;
begin
   Result := '';
   if not Assigned(mStringGrid) then Exit;
      for J := mStringGrid.Selection.Top to mStringGrid.Selection.Bottom do
         begin
           S := '';
           for I := mStringGrid.Selection.Left to mStringGrid.Selection.Right do
           S := S + #9 + mStringGrid.Cells[I, J];
             Delete(S, 1, 1);
           Result := Result + S + #13#10;
        end;
   end; { StringGridSelectText }
procedure StringGridPasteFromClipboard(mStringGrid: TStringGrid);
var
vTextList: TStringList;
vLineList: TStringList;
I, J: Integer;
begin
   vTextList := TStringList.Create;
   vLineList := TStringList.Create;
   vLineList.Delimiter := #9;
    try
      vTextList.Text := Clipboard.AsText;
        for J := 0 to vTextList.Count - 1 do
         begin
            if J + mStringGrid.Row >= mStringGrid.RowCount then Break;
               vLineList.DelimitedText := vTextList[J];
                 for I := 0 to vLineList.Count - 1 do
         begin
            if I + mStringGrid.Col >= mStringGrid.ColCount then Break;
               mStringGrid.Cells[I + mStringGrid.Col, J + mStringGrid.Row] := vLineList[I];
         end;
end;
finally
vTextList.Free;
vLineList.Free;
end;
end; { StringGridPasteFromClipboard }
procedure StringGridCopyToClipboard(mStringGrid: TStringGrid);
begin
     Clipboard.AsText := StringGridSelectText(mStringGrid);
end; { StringGridCopyToClipboard }
procedure TForm1.MenuItemCopyClick(Sender: TObject);
begin
    StringGridCopyToClipboard(StringGrid1);
end;
procedure TForm1.MenuItemPasteClick(Sender: TObject);
begin
    StringGridPasteFromClipboard(StringGrid1);
end;
procedure TForm1.StringGrid1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
   if ssCtrl in Shift then
     case Key of
     Ord('C'): StringGridCopyToClipboard(TStringGrid(Sender));
     Ord('V'): StringGridPasteFromClipboard(TStringGrid(Sender));
   end;
end;
 


标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@evget.com


为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP