How to get the items and subitems in a listview?

有些话、适合烂在心里 提交于 2019-12-11 10:44:34

问题


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

Here's my code:

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

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


回答1:


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.



来源:https://stackoverflow.com/questions/1148267/how-to-get-the-items-and-subitems-in-a-listview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!