开发者

How to copy multiple selected rows of listview into clipboard in Delphi

I have put together this code Selected rows into clipboard from a lisview.

procedure TFmainViewTCP.Copy1Click(Sender: TObject);
 var
  Str:String;
  k  :Integer;
  lItem:TListItem;
 begin
   repeat
     lItem:=lvConnection.Selected;
     Str:=lItem.Caption;
     for k:=0 to lvConnection.Columns.Count-2 do
      begin
       Str:=Str+'  '+lItem.SubItems[k];
      end;
     Clipboard.AsText:=Clipboard.AsText+ sLineBreak +Str; {copy into clipboard}
   until lItem.Selected=True;
 end;

I am not sure if this is working correctly, it does not copy out all the rows for me. Can somebody help me out in this?

Th开发者_开发技巧anks in Advance


your code does not iterate over all of the selected rows. It just works on the first selected. You need to loop on all the items and process the selected ones...

procedure TFmainViewTCP.Copy1Click(Sender: TObject);
 var
  s, t: String;
  i: Integer;
  lItem: TListItem;
 begin
  t := '';
  lItem := lvConnection.GetNextItem(nil, sdBelow, [isSelected]);
  while lItem <> nil do
  begin
    s := lItem.Caption;
    for i := 0 to lItem.SubItems.Count-1 do
      s := s + '  ' + lItem.SubItems[i];
    t := t + s + sLineBreak;
    lItem := lvConnection.GetNextItem(lItem, sdBelow, [isSelected]);
  end;
  if t <> '' then Clipboard.AsText := t;
 end;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜