function TForm1.getlistviewtext(lv: TListView;flag:Integer): string;
var
  i,j,m,n:Integer;
  s,s1,s2:string;
begin
  result:='';
  s:='';
  i:=lv.Columns.Count;
  m:=lv.Items.Count;
  //得出列标题
  for j:=0 to i-1 do
  begin
    s:=lv.Columns[j].Caption;
    if flag=1 then//需要将标题内容一起取出
      result:=result+s;
  end;
  //得出单元格所有内容
  for n:=0 to m-1 do
  begin
    s1:=self.ListView1.Items[n].Caption;
    result:=result+s1;
    for j:=0 to i-2 do
    begin
      s2:=self.ListView1.Items[n].SubItems[j];
      result:=result+s2;
    end;
  end;
end;如果我要将ListView1中的内容中每行的X,Y列逐条取出,要怎么写呢?

解决方案 »

  1.   

    说错了,是要将ListView2中全选的内容每行的X,Y列逐条取出,要怎么写呢?ListView2红的数据是从ListView1中添加过来的
      

  2.   

    你listview2的rowselect设置成true还是false?
      

  3.   

    可以简单的改成这样function TForm1.getlistviewtext(lv: TListView;flag:Integer): string;
    var
      i,j,m,n:Integer;
      s,s1,s2:string;
    begin
      result:='';
      s:='';
      i:=lv.Columns.Count;
      m:=lv.Items.Count;
      //得出列标题
      for j:=0 to i-1 do
      begin
        s:=lv.Columns[j].Caption;
        if flag=1 then//需要将标题内容一起取出
          result:=result+s;
      end;
      //得出单元格所有内容
      for n:=0 to m-1 do
      begin
        if lv.Items[n].Selected then
        begin
          s1:=lv.Items[n].Caption;
          result:=result+s1;
          for j:=0 to i-2 do
          begin
            s2:=lv.Items[n].SubItems[j];
            result:=result+s2;
          end;
        end;
      end;
    end;
      

  4.   


    还是不怎么明白,我这个是个歌曲下载软件,我要把ListView2中的歌曲下载到U盘,当点“下载”按钮的时候,它就把ListView2中全部的 歌曲路径+歌曲名字得到文件路径,下载到U盘
    listview2的rowselect设置成true老大在帮忙看下,万分感谢,不知道你是哪里的,不然请你吃饭,呵呵!
      

  5.   

    你的listview结构什么样?能不能发张图上来,不然只能按照我的想法写了
      

  6.   

    参考代码procedure TForm1.Button12Click(Sender: TObject);
    var
      i,j,m,n:Integer;
      s,s1,s2:string;
    begin
      s:='';
      i:=self.ListView1.Columns.Count;
      m:=self.ListView1.Items.Count;
      //得出单元格所有内容
      for n:=0 to m-1 do
      begin
        if self.ListView1.Items[n].Selected then
        begin
          s1:=self.ListView1.Items[n].Caption;//歌曲路径
          s2:=self.ListView1.Items[n].SubItems[0];//歌曲名称
          self.Memo1.Lines.Add(s1+s2);
          //拷贝该歌曲
        end;
      end;
    end;