ListView

Posted by Kim on April 22, 2005

I'm new in Delphi-programming and I like to have a multiselect ListView. My ListView-box is dynamicly filled like this:

try
  Open;
  while not(EOF) do begin
    if FieldByName('PRICELIST').AsString = 'Y' then begin
      APricingListItem         := lvwProductSelection.Items.Add;
      APricingListItem.Data    := Pointer(FieldByName('ID').AsInteger);
      APricingListItem.Caption := FieldByName('PRODUCTNAME').AsString;
      APricingListItem.SubItems.Add(FieldByName('PRODUCTSIZE').AsString);
      APricingListItem.SubItems.Add(FieldByName('PRODUCTPACK').AsString);
      APricingListItem.SubItems.Add(FieldByName('PRODUCTWEIGHT').AsString);
      APricingListItem.SubItems.Add(FieldByName('UKPOUNDPRICE').AsString);
      APricingListItem.SubItems.Add(FieldByName('UKEUROPRICE').AsString);
      APricingListItem.SubItems.Add(FieldByName('EUEUROPRICE').AsString);
    end;
  end;

What I want is to put the ID's (Data) of the selected items in a string, but all I can seem to select is the Caption.

Somehow the ListView is not explained well on the internet and in books, so can anyone help me?

Reply by Kim on April 22, 2005

I found the solution to my problem...:

var
  iID:    integer;
  iIndex: integer;
begin
  iIndex := lvwProductSelection.ItemFocused.Index;
  iID    := integer(lvwProductSelection.Items.Item[iIndex].Data);
  ....
  ...
end;