请各位大侠帮帮忙,怎么把DBGrid中的数据赋值给TListView?
谢谢!

解决方案 »

  1.   

    我要得到,在DBGrid中显示的数据,放到TListView中显示
      

  2.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
     i : integer;
     aListItem: TListItem;
    begin
      with  DBGrid1.DataSource.DataSet do
        begin
          First;
          while not Eof do
            begin
              aListItem :=ListView1.Items.Add;
              aListItem.Caption := FieldByName('ID').AsVariant;
              aListItem.SubItems.Add ( FieldByName('FiledName').asstring );
              aListItem.SubItems.Add ( FieldByName('FiledName').asstring);
              
            end;
        end;
    end;
      

  3.   

    var
     i : integer;
     aListItem: TListItem;
    begin
      with  DBGrid1.DataSource.DataSet do
        begin
          First;
          while not Eof do
            begin
              aListItem :=ListView1.Items.Add;
              aListItem.Caption := FieldByName('ID').AsVariant;
              aListItem.SubItems.Add ( FieldByName('FiledName').asstring );
              aListItem.SubItems.Add ( FieldByName('FiledName').asstring);
              Next;
            end;
        end;
    end;
      

  4.   

    ListView1.ViewStyle :=  vsReport;
      

  5.   

    我对DBGrid里面的数据修改,或删除了某些数据后但在数据库中没有删除,上面的代码能实现吗?