如何在列表视图中获取项目和子项目?

如何在列表视图中获取项目和子项目?

问题描述:

我想在列表视图中获取所有项和子项,但我得到的只是"TlistItem"

I want to get all items and subitems in my listview,but all I get is "TlistItem"

这是我的代码:

procedure TFrameAnalyzer.AddEntry(opcode:word;data:Array of byte;direction:byte);
begin
  MessageBox(0,PChar(sListView1.Items.Item[4].ToString),'',0);
end;

如何获取项目名称作为字符串及其2个子项目的名称?

How do I get the name of the item as string and the name of it's 2 subitems?

您无法获取该商品的名称,因为它没有名称.但是,它具有Caption和类型为TStringsSubItems属性.所有这些都可以在Delphi文档BTW中轻松找到.查看TListItemTListItems类.

You can't get the name of the item, because it has no name. It has a Caption though, and a SubItems property of type TStrings. All of this can easily be found in the Delphi documentation BTW. Look into TListItem and TListItems classes.

所以您可以做类似的事情

So you could do something like

procedure TFrameAnalyzer.AddEntry(opcode:word;data:Array of byte;direction:byte);
var
  Item: TListItem;
  s: string;
begin
  Item := sListView1.Items.Item[4];
  s := Item.Caption + #13#10
    + '  ' + Item.SubItems[0] + #13#10
    + '  ' + Item.SubItems[1];
  MessageBox(0, PChar(s), nil, 0);
end;

所有错误处理都被省略了,您一定不应该先检查索引是否有效才以这种方式访问​​数组属性.

All error handling omitted, you should certainly not access array properties in this way without checking first that the indices are valid.