首页 > 解决方案 > 如何从 C++ 中的列表视图中获取值

问题描述

我正在使用 C++ Builder 2010。我想知道,如何从 ListView 组件中获取值?是否有可能仅从第二列(例如)获得价值。我发现了很多关于向ListView添加值的信息,而不是阅读.

标签: c++listviewc++builder

解决方案


添加新项目时,该方法TListItems::Add()返回一个TListItem*. 要访问现有项目,您可以使用相同TListItems的方法获取TListItem*所需项目的 a,例如:

// get the desired item by its index in the list...
TListItem *Item = ListView1->Items->Item[index];

在任何给定项目中,第一列由TListItem::Caption属性表示,后续列由TListItem::SubItems属性表示。因此,就像使用添加值时一样SubItems,您可以使用SubItems来读取值,例如:

String value = item->SubItems->Strings[0]; // 0 = 2nd column, 1 = 3rd column, etc...

推荐阅读