0

I have a TListView on my form. I add some columns in it depending on the input like so:

 MyItem := StringListView.Columns.Add;
 MyItem.Caption := IntToStr(i);
 MyItem.Width := -2;

Afterwards I use the onData event to populate the ListView like this:

procedure TMatrixDictViewerFrame.StringListViewData(Sender: TObject;
  Item: TListItem);
var
  ItemCaption: string;
  ItemText: string;`

begin 

    ItemCaption := Format('[%d]', [Item.Index]);
    ItemText := FItems[Item.Index];

    Item.Caption := ItemCaption;
    Item.SubItems.Add(ItemText);

end;

It works fine since in the First column I have the Itemcaptions and in the second column I get the Itemtexts. What I couldnt figure out tho is how to populate the ListView depending on the data I get. For example: I have a matrix A which is a 3x3 Matrix and I want its elements to be shown in this ListView so the first row shows the first 3 row elements, the second row shows the second row three elements and so on. Questions: how can I access the third column? How can I populate the view according to the Index I have (i,j)?

Best regards

4

1 回答 1

0

Index列表项的属性告诉您行。您应该填充整行。像这样:

procedure TMatrixDictViewerFrame.StringListViewData(Sender: TObject; Item: TListItem);
begin 
  // A is a 3x3 matrix, that you obtain by means we don't know
  Item.Caption := FloatToStr(A[Item.Index, 0]);
  Item.SubItems.Add(FloatToStr(A[Item.Index, 1]));
  Item.SubItems.Add(FloatToStr(A[Item.Index, 2]));
end;
于 2015-10-09T12:26:45.460 回答