如何在列表视图中获取项目和子项目? [英] How to get the items and subitems in a listview?
问题描述
我想在列表视图中获取所有项和子项,但我得到的只是"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
和类型为TStrings
的SubItems
属性.所有这些都可以在Delphi文档BTW中轻松找到.查看TListItem
和TListItems
类.
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.
这篇关于如何在列表视图中获取项目和子项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!