如何在列表视图中获取项目和子项目? [英] How to get the items and subitems in a listview?

查看:149
本文介绍了如何在列表视图中获取项目和子项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在列表视图中获取所有项和子项,但我得到的只是"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.

这篇关于如何在列表视图中获取项目和子项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆