I have a List View with eight columns and a popup menu.
[ScreenShot]
I have this code which is work great to copy into clipboard all items and sub items when a row or all rows selected.
procedure TForm1.CopyURL1Click(Sender: TObject);
var
lv : TbsSkinListView;
s : string;
c,f,k : integer;
begin
lv := bsSkinListView1;
Clipboard.Clear;
s := '';
for f := 0 to lv.Items.Count - 1 do
begin
k := 0;
if lv.Items[f].Selected then
begin
s := s + Format('%s : %s, ',[lv.Columns[k].Caption, lv.Items[f].Caption]);
for c := 0 to lv.Items[f].SubItems.Count - 1 do
begin
Inc(k);
s := s + Format('%s : %s, ',[lv.Columns[k].Caption, lv.Items[f].SubItems[c]]);
end;
SetLength(s, Length(s) - 2);
s := s + #$D#$A;
end;
end;
clipboard.AsText := s;
end;
What i need is I'd like to copy only the caption of column one (column "Title") with it's sub items [0], and copy the column 8 caption (column "URL") with it's sub items [7] into clipboard, when a row or all rows selected.
Also sometime sub items[7] is empty, and it shouldn't get index out of bounds (7) error message.
From my screenshot above, when i copy the 1st row, the result should return like this
Title : 10 Things You Didn't Know... URL : <=== this is an empty sub items [7]
when 2nd row copied:
Title : 10 Things You Didn't Know... URL : http://www.example.com
All rows selected :
Title : 10 Things You Didn't Know... URL :
Title : 10 Things You Didn't Know... URL : http://www.example.com
i have try this link but it doesn't meet or not work as i need. I'm using Delphi XE 4. How do i achieve this? Any help would be highly appreciated.