我已将此代码放在一起,将所选行从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;
我不确定这是否正常工作,它不会为我复制所有行。有人可以帮助我吗?
先谢谢
答案 0 :(得分:4)
您的代码不会遍历所有选定的行。它只适用于第一个选定的。您需要循环所有项目并处理所选项目......
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;