Board index » delphi » TListView getting access to items

TListView getting access to items

Hi there

Can anybody help.

I am having a problem getting access to individual cells/items within a
TlistView component.  This is so that I can pass these values to an another
form. Any code help would be great.

regards
Baber

 

Re:TListView getting access to items


On Wed, 2 Aug 2000 11:48:55 +0100, "Baber Safdar"

Quote
<bsaf...@hotmail.com> wrote:
>I am having a problem getting access to individual cells/items within a
>TlistView component.  This is so that I can pass these values to an another
>form. Any code help would be great.

A list view is basically an arbitrary list of items (of type
TListItem). You can fetch the first item in this list by looking at
the TListView.TopItem property.

You can determine the length of the list by checking out
TListView.Items.Count.

You can access any of the individual items by referencing that
particular TListItem through TListView.Items[index]

Within one TListItem, you have a number of properties you might be
interested in. One is the Caption property, the text that you'll see
associated with the TListItem.

If you have a list view in the vsReport style, you might have
additional columns of text. These are the strings in the
TListItem.SubItems string list.

So, if you need to access the third items of a list view, you'd go
like this:

var
   oListItem : TListItem;
begin
   oListItem := ListView1.Items[2];  // index is 0-based

To access the caption, you write:

  DoSomething(oListItem.Caption);

To loop through the subitems, you'd go like this:

  for ix := 0 to oListItem.SubItems.Count-1 do begin
      DoSomething(oListItem.SubItems[ix]);

Hope that helps!

Marc

------------------------------------------------------------------------
Marc Scheuner                                          Software Engineer
FastLane Technologies Inc.                  Halifax, Nova Scotia, Canada
Email: mailto:mscheu...@fastlane.com

Plan, Deploy, Manage Windows 2000 with FastLane DM/Suite.
Optimize Windows 2000 now!
http://www.fastlane.com

Re:TListView getting access to items


Quote
>Baber Safdar wrote:

> I am having a problem getting access to individual cells/items within > a TlistView component.  This is so that I can pass these values to an > another form. Any code help would be great.

Several methods return a ListItem, e.g.

  if Assigned(ListView.Selected) then
    s := ListView.Selected.Caption;
or
    s := ListView.GetItemAt(x, y).Caption;   // use e.g. in OnMouseDown

To access subitems:

  s := ListView.Selected.Subitems[0];
________
Andreas
Delphi 5.01 Pro, NT4.0 Sp5
Direct replies mailto:p...@augsburg.netsurf.de

Other Threads