现在想实现把tlistview组件的数据删除的方法
listview的格式如下:
序号 名称
1   aaa
2   bbb
3   ccc
4   ddd
用listview的DblClick事件来写,如下:
if listview1.Selected<>nil then
  listview1.Selected.Delete;
  listview1.Refresh;
  listview1.Arrange(arAlignTop);
能删除了,但是序号没有重新刷新,例如删除了序号3,显示的序号是1,2,4.怎么能刷新序号那列呢?还有一个问题就是在4条记录之间拖拽,例如把记录3拖拽到第一行,然后在把序号列进行重新排序,调整后变成:
序号 名称
1   ccc
2   aaa
3   bbb
4   ddd
...麻烦高手在帮忙解决下~!谢谢~!

解决方案 »

  1.   

    序号你可以自己生成,即让它自动生成不就得了,每进行一次数据的处理,执行一次处理,如
    for i:=0 to listview1.items.count-1 do
    listview1.items[i].caption:=inttostr(i+1);
      

  2.   

    序号你可以自己生成,即让它自动生成不就得了,每进行一次数据的处理,执行一次处理,如 
    for i:=0 to listview1.items.count-1 do 
    listview1.items[i].caption:=inttostr(i+1);顶
      

  3.   

    var
      Form1: TForm1;
      Draging:Boolean=false;
      BeginDragItem:TListItem;
    implementation{$R *.dfm}procedure TForm1.ListView1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    begin
    BeginDragItem:=ListView1.GetItemAt(x,y);
    Draging:=true;
    end;procedure TForm1.ListView1MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    var
    item:TListitem;
    str:string;
    begin
    if Draging then
       begin
       if BeginDragItem<>nil then
          begin
          item:=ListView1.GetItemAt(x,y);
          if item<>nil then
             begin
             str:=BeginDragItem.SubItems[0];
             BeginDragItem.SubItems[0]:=item.SubItems[0];
             item.SubItems[0]:=str;
             item.Selected:=true;
             end;
          end;
       end;
    end;