如何显示如下格式的listview.
序号 名称
0   aaa
1   bbb
2   ccc
3   ddd
..  ...
listview显示选择了report,定义了2列,分别为序号,名称。
现在要把从数据库中取出的数据填充进去。
序号是根据数据条数计算出来的,名称是截取出来的字符串。数据库内部的格式为aaa;bbb;ccc;ddd;...;
很着急呀。各位知道的给帮帮忙?

解决方案 »

  1.   

    从数据库中读取数据向listview写,做循环就可以了,这样序号就可以写进来了
    对于aaa,bbb:ccc:ddd不知这你这是一条记录还是多条,如果是多条就分开一条条写,可以用一个stringlist来处理。
    类似这样,具体处理的自己修改一下吧
        with ListView1.Items.Add do
        begin
          Caption := FOtherCostInfo.othername;
          SubItems.Add(FOtherCostInfo.othercost);
        end;
      

  2.   

    var 
     s:tlistitem;
     i:Integerp
    begin
     循环{  
    //======先准备号填充数据;
       s:=listview.items.add;
       s.caption:='序号值';
       s.subitems.add('名称值')
      }
    end;
      

  3.   

    谢谢楼上几位的回答,添加数据搞定了,如何能够实现listview里面每条记录的拖拽呀,拖拽之后在重新排序,谢谢哦。
      

  4.   

    我那个长串是一条记录,中间有分隔符号,自己截字符串就分成aaa,bbb,ccc,的格式了。
    现在不知道怎么实现拖拽的效果,是托行,不是托列。
      

  5.   

    var
      i:Integer;
      strlist:TStringList;
    begin
      strlist:=TStringList.Create;
      strlist.Delimiter := ';';
      strlist.DelimitedText := 'aaa;bbb;ccc;ddd';
      for  i:=0 to strlist.Count-1 do
      begin
        with ListView1.Items.Add do
        begin
          Caption := IntToStr(i);
          SubItems.Add(strlist.Strings[i]);
        end;
      end;
    end;
      

  6.   

    谢谢楼上几位的回答,添加数据搞定了,如何能够实现listview里面每条记录的拖拽呀,拖拽之后在重新排序,谢谢哦。
    要不我在开一贴呀?
      

  7.   

    怎么能实现用鼠标来拖拽listview中显示的每条记录,改变位置呀?
      

  8.   

    具体程序给你:
    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;