如何将列表视图的多个选定行复制到Delphi中的剪贴板中 [英] How to copy multiple selected rows of listview into clipboard in Delphi

查看:251
本文介绍了如何将列表视图的多个选定行复制到Delphi中的剪贴板中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将这段代码放在一起,从lisview中选择行到剪贴板。

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?

在此先感谢

推荐答案

您的代码不会遍历所有选定的行。它仅适用于第一个选定的对象。您需要循环浏览所有项目并处理选定的项目...

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;

这篇关于如何将列表视图的多个选定行复制到Delphi中的剪贴板中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆