Board index » delphi » How do I read subitems from ListView?

How do I read subitems from ListView?

I am putting items into a ListView component.  I have a caption, the
first subitem holds a description, and the second subitem holds a cost.
How do I access the second subitem (cost) when I want to read it back.

Here is what I do to put the items into the ListView component.

procedure AddToListView(sStr1, sStr2 : String);
var  
   lstitmLocalItem : TListItem;
begin  
   lstitmLocalItem := frmMain.ListView1.Items.Insert(0);
   lstitmLocalItem.Caption := FormatDateTime('mm/dd/yy', Date);
   lstitmLocalItem.SubItems.Add(sStr1);
   lstitmLocalItem.SubItems.Add(sStr2);
end;

Thanks in advance.

 

Re:How do I read subitems from ListView?


Quote
Charles Josh wrote:

> I am putting items into a ListView component.  I have a caption, the
> first subitem holds a description, and the second subitem holds a cost.
> How do I access the second subitem (cost) when I want to read it back.

> Here is what I do to put the items into the ListView component.

> procedure AddToListView(sStr1, sStr2 : String);
> var
>    lstitmLocalItem : TListItem;
> begin
>    lstitmLocalItem := frmMain.ListView1.Items.Insert(0);
>    lstitmLocalItem.Caption := FormatDateTime('mm/dd/yy', Date);
>    lstitmLocalItem.SubItems.Add(sStr1);
>    lstitmLocalItem.SubItems.Add(sStr2);
> end;

> Thanks in advance.

The SubItems is a TStrings. You can access your subitems by using the
following statement:

TheSubItemString := TheListItem.SubItems[SubItemNumber];

Svein Dybvik
O.A.Halvari AS
E-mail: halv...@sn.no

Other Threads