Board index » delphi » Filling ListView with data

Filling ListView with data

How can I fill a ListView component with data from dbtable?

Mario Gielissen

 

Re:Filling ListView with data


Here's a simple example you can adapt:

procedure TForm1.Button1Click(Sender: TObject);
var
   Li: TListItem;
   LC: TListColumn;
   i: integer;
begin
   with ListView1 do
   begin
       LC := Columns.Add;
       LC.Caption := 'Order No';
       Columns[0].Width := 100;
       LC := Columns.Add;
       LC.Caption := 'Amount Paid';
      Columns[1].Width := 100;
       table1.First;
       repeat
           Li := Items.Add;
           Li.Caption := Table1.fieldbyname('OrderNo').AsString;
           li.SubItems.add(Table1.FieldByName('AmountPaid').AsString);
           Table1.Next;
       until Table1.EOF;
   end;

end;

********************************
Michael Glatz
glatzfa...@aol.com
mgl...@briefcase.com

Re:Filling ListView with data


This is the example from the last message, but modified to show you how to
synchronise a listvioew with your data...

procedure TForm1.Button1Click(Sender: TObject);
var
   Li: TListItem;
   LC: TListColumn;
   i: integer;
begin
   with ListView1 do
   begin
       LC := Columns.Add;
       LC.Caption := 'Order No';
       Columns[0].Width := 100;
       LC := Columns.Add;
       LC.Caption := 'Amount Paid';
      Columns[1].Width := 100;
       table1.First;
       repeat
           Li := Items.Add;
           Li.Caption := Table1.fieldbyname('OrderNo').AsString;
------->  Li.Data := Table1.GetBookMark;  <-----------------  Insert this
line
           li.SubItems.add(Table1.FieldByName('AmountPaid').AsString);
           Table1.Next;
       until Table1.EOF;
   end;

then, in the OnChange event of the listview, something like this ....

if item <> nil then {this is important}
        Table1.GotoBookmark(item.data);
//Once at the right record, you can use the table to populate some other
control...

HTH

Stu

Mario Gielissen <mario.gielis...@mgis.demon.nl> wrote in article
<907343121.11632.0.spot.c3ade...@news.demon.nl>...

Quote
> How can I fill a ListView component with data from dbtable?

> Mario Gielissen

Other Threads