如何在listview中指定位置加入数据,例如在第2行第5列插入 yes  在第3行第6列插入 no

解决方案 »

  1.   


      ListView1.Items[2].Caption;
      ListView1.Items[2].SubItems[5] := 'yes';
      

  2.   

    注意索引是从0开始,上面的item[2]其实是第三条记录,第二天是item[1]
      

  3.   

    但是报错
    access violation as address 0049bcad in module 'project2.exe'.
    read of address 00000008
      

  4.   

    list index out of bounds
      

  5.   


    你取得COUNT後,用下面這個方法INSERT  ListView1.Items.Insert()
      

  6.   

    请问starluck
    如何取得count
    如果可以的话请
    给一个完整的例子代码
      

  7.   

    //先初始化listview
    procedure TForm1.FormCreate(Sender: TObject);
    var
      i,j: integer;
    begin
      ListView1.Items.Clear;
      for i:=0 to 10 do
      begin
        with listView1.Items.Add do
        begin
          listView1.Items[i].caption := inttostr(i);
          for j:=0 to 4 do
          begin
            listView1.Items[i].SubItems.Add('');
          end;
        end;
      end;
    end;
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      listview1.Items[listview1.Selected.Index].SubItems[strtoint(edit1.Text)] := trim(Edit2.Text);
    end;在选中的行的[strtoint(edit1.Text)]第几列加值
      

  8.   

    listview的subitems需要先add,否则会提示错误。
    可以通过增加一个edit控件,在点击listview的单元格的事件中设置edit控件的left、top值,
    在edit的Onchange事件中,给选择的单元格的值等于edit.text。选择哪一行可以根据listview.selected来确定。
    怎么确定选择的是选定行的哪个单元格呢?通过columns的宽度和鼠标的坐标来判断。以上是我的一点思路,仅供参考。