Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Basic Syntax - Populating a List view

Status
Not open for further replies.

CAFCrew

Programmer
Jan 5, 2005
58
GB
Hi ,

I am currently trying to teach myself Delphi, but I am stuggling a little with finding how to populate a list view with information for a DB table. I have looked on all the usual places, but i cant find examples anywhere.

Can someone help?

Many thanks in advance for your help

Matt
 
Lets say you have a TListView named MyList (which is created) and a data record with three strings.

Furthermore, you have a function GetNextRecord, able to return the next dbase record or tell you the dbase is ended.

type
TData = record
dName : AnsiString;
dAddress : AnsiString;
dPhone : AnsiString;
end;
var
LI : TListItem;
Data : TData;
begin
{GetNexRecords returns True if a record has been read
into Data; False otherwise.}
while GetNextRecord(Data) do
begin
{Ask the list to create and add a new ListItem}
LI := MyList.Items.Add;
{And fill it}
LI.Caption := Data.dName;
LI.SubItems.Add(Data.dAddress); // Column 0
LI.SubItems.Add(Data.dPhone); // Column 1
end;
end;

ListView contents:
CAPTION COL 0 COL 1
Name1 Address1 Phone1
Name2 Address2 Phone2
Name3 Address2 Phone3

In styles vsList and vsReport you are going to see all the columns; in styles vsIcon or vsSmallIcon only the caption. The data is there any way.

HTH
buho (A).

 
Thanks to both of you...all sorted now :D

Matt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top