在LIstView控件中怎么使用SaveDialog控件保存内容?
为什么还要判断SaveDialog.execute?
最好有这方面代码,谢谢!

解决方案 »

  1.   

    保存内容???楼主好像问得不够清晰。。
    是ListView中的内容吗??
    以什么文件形式来保留?.txt ?? .ini ??还是……
      

  2.   

    SaveDialog.execute判断用户是选择了文件还是取消了我不知道你要保存什么
      

  3.   

    这个容易阿
    给你写个代码:procedure SaveListViewToText(ListView: TListView; FileName: String);
    var
      TF:TextFile;
      I: Integer;
    begin
      AssignFile(TF, FileName);
      ReWrite(TF);
      for I := 0 to Pred(ListView.Items.Count) do
      begin
        with ListView.Items[I] do
          Writeln(TF,  Caption + #9 + SubItems[0] + #9 + SubItems[1]......{具体按照你的实际情况添加});
      end; 
     CloseFile(TF);  
    end;上面的代码就可以把listview的内容保存下来。
    建议根据你的其他代码使用 try...finally...结构。
    务必记得CloseFile.
      

  4.   

    忘记说了,用savedialog的方法with SaveDialog1 do
    begin
    if Execute then
      SaveListViewToText(FileName);
    end;
      

  5.   

    上面写错了,我晕;
    是 saveListViewToText(ListView1, FileName);
      

  6.   

    delphi帮助当中的例子!!是stringgrid,意思一样了procedure TForm1.Button1Click(Sender: TObject);
    var
      BackupName: string;
      FileHandle: Integer;
      StringLen: Integer;
      X: Integer;
      Y: Integer;
    begin
      if SaveDialog1.Execute then
      begin
        if FileExists(SaveDialog1.FileName) then
        begin
          BackupName := ExtractFileName(SaveDialog1.FileName);
          BackupName := ChangeFileExt(BackupName, '.BAK');
          if not RenameFile(SaveDialog1.FileName, BackupName) then        raise Exception.Create('Unable to create backup file.');
        end;
        FileHandle := FileCreate(SaveDialog1.FileName);
        { Write out the number of rows and columns in the grid. }
        FileWrite(FileHandle, 
          StringGrid1.ColCount, SizeOf(StringGrid1.ColCount));
        FileWrite(FileHandle, 
          StringGrid1.RowCount, SizeOf(StringGrid1.RowCount));
        for X := 0 to StringGrid1.ColCount ?1 do
        begin      for Y := 0 to StringGrid1.RowCount ?1 do
          begin
            { Write out the length of each string, followed by the string itself. }
            StringLen := Length(StringGrid1.Cells[X,Y]);
            FileWrite(FileHandle, StringLen, SizeOf(StringLen));
            FileWrite(FileHandle,
              StringGrid1.Cells[X,Y], Length(StringGrid1.Cells[X,Y]);
          end;
        end;
        FileClose(FileHandle);
      end;end;
      

  7.   

    我想将ListView中的内容保存为.mdb格式?
    如何实现!
    谢谢
      

  8.   

    mdb好像不可以吧
    直接点,保存为dat,create一个文件流就可以做到了
      

  9.   

    如果ListView的列固定,可以保存到数据库中,这个是最基本的数据库访问了吧,如果是新手,用DbGrid更简单点。
      

  10.   

    to 快乐老猫(无米下炊) 
    谢谢你,我该如何保存到数据库中?就用Listview