我现在已经生成了一个ListView格式如下:
通道   状态    时间    
0001   空闲    17:05   
0002   忙碌    20:24
0003   未知    00:00    
.............
我现在想修改其中的一条记录,比如0001我想改成忙碌,然后刷新对应的这条记录,其他记录不变,我用的是vsReport,有没有方法能够局部刷新,我现在记录比较多,通过socket来接受另外的程序发过来的消息,我可以得到我要更新的消息的结构,如:0001  忙碌 13:03,我根据0001找到对应的记录更新,当着条记录更新就自动刷新该条记录,最好能给点代码参考,谢谢!

解决方案 »

  1.   

    建议用Virtual Listview来处理。
      

  2.   

    Items[1].SubItems.Strings[0] := xx;
    Items[2].SubItems.Strings[0] := xx;
    Items[3].SubItems.Strings[0] := xx;
    ......
      

  3.   

    "建议用Virtual Listview来处理。"
    ListView不能实现吗?Virtual Listview没用过啊
      

  4.   

    Items[1].SubItems.Strings[0] := xx;
    Items[2].SubItems.Strings[0] := xx;
    Items[3].SubItems.Strings[0] := xx;
    ......
    能不能写详细点
      

  5.   

    with ListView do
    begin
      Items[1].SubItems.Strings[0] := xx;
    Items[2].SubItems.Strings[0] := xx;
    Items[3].SubItems.Strings[0] := xx;end;
      

  6.   

    with ListView do
    begin
      Items[1].SubItems.Strings[0] := xx;
    Items[2].SubItems.Strings[0] := xx;
    Items[3].SubItems.Strings[0] := xx;end;
    界面里面的这条记录会自动更新吗?还有我知道0001怎么对应到Items[x]上面?
      

  7.   

    呵呵。Virtual Listview 还是ListView.OwnerData := True;在OnData事件中写入相应代码.
      

  8.   

    Items[i].SubItems.Strings[j] := xx;
    i:横坐标位置,j纵坐标位置,不过I的第一列不是Items[i].SubItems.Strings[0],而是Items[i].Caption
      

  9.   

    我试试看,
    "呵呵。Virtual Listview 还是ListView.OwnerData := True;在OnData事件中写入相应代码.
    "
    ListView中用OwnerData := True;在OnData事件中写入相应代码.可以吗,我不是在界面上面修改值,我是程序内部值改变了在界面上面刷新显示.还有什么好方法吗?我都试试看,可以的话就揭贴了/
      

  10.   

    呵呵,这个就是达到你的目的,因为Virtual Listview自身是没有任何数据的,全部依赖你的外部数据集。
      

  11.   

    外部数据集一旦变化,Listview的显示也会同步变化。我的数据是十万多条测试的哈。一瞬间的事情。
      

  12.   

    Virtual Listview有没有代码参考能不能给我发点,[email protected],谢谢
      

  13.   

    ...\Borland\Delphi7\Demos\Virtual Listview
      

  14.   

    全心全意为社员服务,我照您的意思写了一个演示。TChannelStatus = packed record
        ChannelNo: string;
        Status: string;
        Time: string;
      end;
      PTChannelStatus = ^TChannelStatus;  TForm1 = class(TForm)
        ListView: TListView;
        ButtonNew: TButton;
        ButtonUpdate: TButton;
        procedure ListViewData(Sender: TObject; Item: TListItem);
        procedure FormCreate(Sender: TObject);
        procedure ButtonNewClick(Sender: TObject);
        procedure ButtonUpdateClick(Sender: TObject);
      private
        FList: TList;
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.ListViewData(Sender: TObject; Item: TListItem);
    begin
      Item.Caption := PTChannelStatus(FList.Items[Item.Index]).ChannelNo;
      Item.SubItems.Add(PTChannelStatus(FList.Items[Item.Index]).Status);
      Item.SubItems.Add(PTChannelStatus(FList.Items[Item.Index]).Time);
    end;procedure TForm1.FormCreate(Sender: TObject);
    var
      Idx: Integer;
    begin
      FList := TList.Create;
      ListView.DoubleBuffered := True;
      with ListView.Columns.Add do
      begin
         Caption := '通道';
         Width := 150;
      end;
      with ListView.Columns.Add do
      begin
         Caption := '状态';
         Width := 150;
      end;
      with ListView.Columns.Add do
      begin
         Caption := '时间';
         Width := 150;
      end;
    end;procedure TForm1.ButtonNewClick(Sender: TObject);
    var
      _TChannelStatus: array[0..999] of PTChannelStatus;
      Idx: Integer;
    begin
      for Idx := 0 to 999 do
      begin
        New(_TChannelStatus[Idx]);
        _TChannelStatus[Idx].ChannelNo := '000'+Trim(IntToStr(Idx+1));
        _TChannelStatus[Idx].Status := '空闲';
        _TChannelStatus[Idx].Time := FormatDateTime('HH:MMMM:SS', Now);
        FList.Add(_TChannelStatus[Idx]);
      end;
      ListView.Items.Count := FList.Count;
    end;procedure TForm1.ButtonUpdateClick(Sender: TObject); 
    begin
      PTChannelStatus(FList.Items[3]).Status := '忙碌';
      PTChannelStatus(FList.Items[3]).Time := FormatDateTime('HH:MMMM:SS', Now);
      ListView.Refresh;
    end;
      

  15.   

    '000'+Trim(IntToStr(Idx+1)) 不好,应该改为Format('%.4d',[idx+1])
    至于在实际应用中你的记录集如何实时修改,你根据你的实际情况写吧。